Nuxt Auth middleware redirect seems to fires before the store is initialized #1522
Replies: 18 comments
-
Did you run your app inside a docker container and in ssr mode ? |
Beta Was this translation helpful? Give feedback.
-
I am not using docker, but if i just switch from SSR to SPA it works well...so the problem seems to be in SSR mode |
Beta Was this translation helpful? Give feedback.
-
i'm facing exactly the same issue if i just switch from SSR to SPA it works as expected... but i need the app to be a SSR. |
Beta Was this translation helpful? Give feedback.
-
Can nuxt reach the host which provides your token ? |
Beta Was this translation helpful? Give feedback.
-
the login and register request are fine so nuxt reach the host, and Laravel return the cookies instead token... how can i check if the base_url is correctly server side? router: {
middleware: ['auth']
},
auth: {
strategies: {
local: {
endpoints: {
login: { url: 'api/auth/login', method: 'post' },
logout: { url: 'api/auth/logout', method: 'post' },
user: { url: 'api/user', method: 'get', propertyName: 'user' }
},
tokenRequired: false,
tokenType: false,
}
},
redirect: {
home: '/admin',
login: '/',
logout: '/',
},
}, |
Beta Was this translation helpful? Give feedback.
-
You can check inside any server side function (like nuxtServerInit in your store/index.js). You can console.log from the context (output will be server side too, in your terminal where you run yarn/npm run dev) |
Beta Was this translation helpful? Give feedback.
-
Good day, it seems I have the same problem, when I update some pages, I am transferred to the username and then redirect to the main page. And I can't understand the logic in this, for example, on the page with the address /user-page throws, but on others there is no . But on an address with triple nesting (blog/user_id/article_id), it always switches to the username. Can you find a way to avoid this behavior? |
Beta Was this translation helpful? Give feedback.
-
We had the same problem and used this workaround on
|
Beta Was this translation helpful? Give feedback.
-
Same issue here. Meanwhile, the @pepeloper workaround works for me. |
Beta Was this translation helpful? Give feedback.
-
same problem. I just use this on auth plugins and called asyncdata on secret page.
secretpage
but need to call user data everytime. :( |
Beta Was this translation helpful? Give feedback.
-
Seems like nxut auth it getting a 401 from Laravel even though all the headers and cookies seem to be fine. So it might also be related to Laravel Sanctum? |
Beta Was this translation helpful? Give feedback.
-
Same here. Also, I initially implemented the auth process (getToken, revokeToken, refreshToken) without Note that in my case, I use the |
Beta Was this translation helpful? Give feedback.
-
For SSR, I'm also having this problem. NodeJS backend. Looks like this line is the problem: https://github.com/nuxt-community/auth-module/blob/dev/src/schemes/cookie.ts#L27 I'm getting the following exception thrown:
|
Beta Was this translation helpful? Give feedback.
-
me too I'm using nuxt ssr with Python Backend. (local schema) |
Beta Was this translation helpful? Give feedback.
-
Try enabling axios https, it might fix the problem:
|
Beta Was this translation helpful? Give feedback.
-
I have this exact same problem. I don't know how to fix this issue. It is pity. Nuxt can't fix this issue. |
Beta Was this translation helpful? Give feedback.
-
This works partially as we don't have information on what was the previous route. I guess it could be overridden via custom middleware but that doesn't solve the issue as it's just wrong init order. I will take a look into this and possibly fix it. |
Beta Was this translation helpful? Give feedback.
-
Did anyone have any luck on this? I know it's an old topic, but I'm facing the same issues right now using a Docker container with Nginx as reverse proxy. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I implemented a local strategy with @nuxt/auth and laravel sanctum as backend using the cookie instead of the token.
Everything seems to work great, but after I log in i am correctly redirected to the home / but if i reload the page the middleware: 'auth' redirects me to the login even if the $auth storage state: isLogged and user are correctly populated. It seems then that the redirects applies before the state is re-initialized after the page reload. Is this possible?
Beta Was this translation helpful? Give feedback.
All reactions