Using $auth module’s redirect in tandem with $router.push in Nuxt.js

Abrar Shariar
Console.log()
Published in
2 min readMar 12, 2020

--

Recently I came across the issue of using the auth module in Nuxt.js and invoking a $router.push in subsequent line of code in the same method. The conundrum began when the lines after the auth.loginWith method did not execute as intended since the page was redirected to the redirect URI.

It has been only a week in the Vue.js land, so I suppose this issue is something faced by many newbies.

Photo by Yeshi Kangrang on Unsplash

So, here goes where it all started:

I have a authenticate() function, whose body looks like:

Now, notice that once the line: 2 gets invoked, the execution is handed over to the auth middleware of nuxt.js. Thus, using a $router.push in line:5 is redundant.

Before we proceed any further, let’s take a look where the auth’s configs are defined:

Go to: nuxt.config.js

Find the key auth

--

--