I have implemented the Nuxt auth module
for my project. To manage the login page, I created a custom middleware called guest.js
, which has the following code:
export default function ({ $auth, store, redirect }) {
if (!process.server) {
if ($auth.$state.loggedIn) {
return redirect('/')
}
}
}
In the Login
component, I have specified the middleware as 'guest'
.
The issue arises when the page is refreshed, as the server-side user status in the auth module is set to false:
{ user: null, loggedIn: false, strategy: 'local' }
I added a small check for this, but it seems that the middleware runs only on the server side during refresh. I am using Universal
mode for Nuxt.
How can I make this work effectively?
Thank you.