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.

Share Improve this question asked Sep 9, 2019 at 16:06 Ryan HRyan H 2,9535 gold badges54 silver badges153 bronze badges 2
  • What's wrong with this.$router.push or this.$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
Add a ment  | 

1 Answer 1

Reset to default 12

You have two ways to do it:

  1. $nuxt.$router.push in actions
  2. 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