admin管理员组文章数量:1279017
I'm building a login/register system as part of an app. I'm using Firebase and Vuex to handle authentication and database information. I have some actions in Nuxt JS that create the user, sign them in and log them out.
I'm trying to implement a redirect after the user has been successfully registered / when they click login, my code is:
export const actions = {
/*
* Create a user
*/
createUser ({mit}, payload) {
this.$fireAuth.createUserWithEmailAndPassword(payload.email, payload.password).then(function(firebaseUser) {
mit('setUser', payload)
}).catch(function(error) {
console.log('error logging in' + error)
});
},
/*
* Log a user into Beacon
*/
login ({mit}, payload) {
this.$fireAuth.signInWithEmailAndPassword(payload.email, payload.password).then(function(firebaseUser) {
mit('setUser', payload)
}).catch(function(error) {
console.log('error logging in' + error)
});
},
/*
* Sign a user out of Beacon
*/
signOut ({mit}) {
this.$fireAuth.signOut().then(() => {
mit('setUser', null)
}).catch(err => console.log(error))
}
}
I'm using Nuxt JS 2.9.2, on Vue JS 2.6.10
I have a few modules.
I've tried using this.router.push('/')
and window.location.href
, but would like to retain the SPA functionality.
I'm building a login/register system as part of an app. I'm using Firebase and Vuex to handle authentication and database information. I have some actions in Nuxt JS that create the user, sign them in and log them out.
I'm trying to implement a redirect after the user has been successfully registered / when they click login, my code is:
export const actions = {
/*
* Create a user
*/
createUser ({mit}, payload) {
this.$fireAuth.createUserWithEmailAndPassword(payload.email, payload.password).then(function(firebaseUser) {
mit('setUser', payload)
}).catch(function(error) {
console.log('error logging in' + error)
});
},
/*
* Log a user into Beacon
*/
login ({mit}, payload) {
this.$fireAuth.signInWithEmailAndPassword(payload.email, payload.password).then(function(firebaseUser) {
mit('setUser', payload)
}).catch(function(error) {
console.log('error logging in' + error)
});
},
/*
* Sign a user out of Beacon
*/
signOut ({mit}) {
this.$fireAuth.signOut().then(() => {
mit('setUser', null)
}).catch(err => console.log(error))
}
}
I'm using Nuxt JS 2.9.2, on Vue JS 2.6.10
I have a few modules.
I've tried using this.router.push('/')
and window.location.href
, but would like to retain the SPA functionality.
-
What's wrong with
this.$router.push
orthis.$router.replace
? – David Weldon Commented Sep 9, 2019 at 16:12 - What's the problem you're having? You don't really ask any questions. – jacob13smith Commented Sep 9, 2019 at 16:13
1 Answer
Reset to default 12You have two ways to do it:
$nuxt.$router.push
in actions- Pass
this.$router.push
as argument in your action, and call where you need.
Hope this helps.
本文标签: javascriptRedirect using Vue Router in Nuxt JS vuexStack Overflow
版权声明:本文标题:javascript - Redirect using Vue Router in Nuxt JS vuex - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741235391a2362912.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论