I am currently facing an Issue in NuxtJS where a method is called twice and a request is therefore sent twice.
This happens in a page and the method which is called twice is created().
I open the page with a parameter like:
http://localhost:3000/mypage?token=123123123
And in the created() Method of the page I call a store dispatch.
created() {
if (this.token === undefined || this.token === null) {
this.$router.push('/login')
} else {
console.log('called created() and sent dispatch')
this.$store.dispatch('thirdPartyLogin', {
token: this.token
})
}
},
The token is parsed via the data property:
data() {
return {
token: this.$nuxt.$route.query.token
}
},
The problem with this is that it is a One Time Token, which means that it is invalid after one use. So after the second call no more success of the request can take place.
Why is the page created twice or created() called twice?