1

I have seen multiple people posting in regards to similar (if not the same issue) but none of the solutions work for me.

I have a standard auth gateway using a local strategy (email, password) and I want to redirect to root (or their dedicated page) on successful auth.

It should be as simple as this.$router.push('/') or this.$router.push(user) but nothing happens at all. This is the code...

async initialise({ commit, state}) {
    this.$toast.info('Initialising...');
    try {
      const { data } = await this.$axios.get(`/initialise/${state.auth.user.shop}`);
      commit('INITIALISE_SHOP', data.shop);
      commit('employees/SET_EMPLOYEES', data.employees, { root: true })
      this.$toast.success('Login Successful');
      this.$router.push('/'); <<< this is the offending line
    } catch (error) {
      this.$toast.error('Unable to fetch schedule data. Please contact the Support Team.');
    }
  }

What's even more weird is if I get rid of ALL the code and just put the router function in it will just not do anything at all.

Let me add to this...

If I add console.log() into the code ANYWHERE it will log. I can put it before the http request, I can put it before the $toast or I can put it AFTER the unsuccessful this.$router.push('') and it will log whatever I'm putting in.

Rue
  • 49
  • 1
  • 10
  • Are you sure this code is even reached? Did you try a `console.log` there? – kissu Sep 12 '21 at 15:16
  • Seems this code is in a store file. Did you check if `this.$router` is defined? Is there any error thrown in the console? – Mythos Sep 12 '21 at 16:09
  • @kissu The code is definitely reached, if I put it first it will run through the whole function. If I ONLY put this code it will just not do anything at all. @Mythos it's definitely defined it's just being ignored. I've also tried `this.$nuxt.$router` and `this._vm.router` – Rue Sep 12 '21 at 17:49
  • Can you please test by using `await dispatch` since you're supposed to use actions rather than mutations at the end. – kissu Sep 12 '21 at 22:01
  • What route are you on when you invoke this code? Does it work if you do smth like `await this.initialise(); await this.$router.push('/')`? Do you by any chance have redirects in other places of your app in watchers? Also you might try to invoke `this.$router.push()` with `await` since it is an async function – transGLUKator Sep 13 '21 at 07:56

0 Answers0