-
Notifications
You must be signed in to change notification settings - Fork 927
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[@nuxtjs/auth-next] - Auth middleware issue with SSR #853
Comments
I have the same problem too |
@RobinBertilsson |
@albertarni, thanks. Sadly I still facing the same issue. Thinking if it could be related to a release of the auth-next package as well? |
Sadly no luck with an older version of auth-next... |
Downgrading didn't do anything for me |
I have found a solution without downgrading axios: #478 (comment) |
It seems this is not only limited to auth-next, I was just helping debug this same issue in an application that uses v4.x |
@israelroldan really? Did the Axios downgrade solution work for you? |
Having the same issue, happens only on page hard refresh. Seems the auth middleware on page refresh gets called before the auth module has chance to verify authentication, hence the redirect |
I think this is not related to auth-next. I created a project from scratch to test this. Only installed nuxt-auth and nuxt-axios. Still have the issue. Also suggested solutions above didn't work for me. |
Ok, for my case setting expire time for auth options solved the problem. I added cookie options to nuxt.config file. The default value for cookies was Session and that was causing the problem.
|
It's definitely a hydration timing issue between SSR and client side. I can clearly see the logged in state being hydrated after the page has loaded, at which point the middleware has already run for auth, and because client side hydration happening after this point is sees as not logged in and redirects to login. Im using auth-next but pretty sure I had the same issue with 4.* although I cannot remember how I solved it annoyingly. Right now im using the sanctum strategy very simply.
|
@albertarni downgrade solution on the Axios module worked for me. |
we just encountered the exact same problem - same setup as @just-tom we also just downgraded to axios nuxt module to 5.12.1... and now SSR works as expected... the change that might cause this looks like it is related to upgrading axios from 0.19.2 to 0.20.0... |
I also encountered the exact problem and the downgrade of axios nuxt module to 5.12.1 worked for me too |
Duplicate of #809 |
Latest version fixes this close this issue |
Closing here since latest version of |
I have an issue with @nuxt/auth-next my login details are being retrieved successfuly bt am not being logged in bt when i use @nuxt/auth everything works fine,what could be the problem please |
I’m still having trouble with this. The route is protected and $auth.loggedIn === true but it keeps redirecting me to the homepage. I’ve tried updating all my packages but so far no luck. |
same issue here. I can't use the auth middleware. To fix it, I used cookie-universal-nuxt and I created my own middleware : // middleware/auth-user.js
export default async function ({ app, redirect }) {
const user = await app.$cookies.get('auth._token.local')
if (!user) {
redirect('/')
}
} then I can use it in my components export default {
middleware: 'auth-user',
} |
This is still an issue even after the upgrade of axios @pi0 |
I was hoping the An overview of my routes, and the desired redirect behavior is as follows: If the user IS NOT authenticated the following should occur:
If the user IS authenticated the following should occur:
My auth relevant
My custom
My
My
My
My
Lastly, do not forget to initialize the Vuex store by at least creating an empty My I hope this helps. 🙏🏻 |
All day lost looking for a solution to this without need to make my own middleware etc (wich is the same as recreting the entire functionality of the library) |
i found the solution if you use proxy for axios |
@RobinBertilsson did u sortout the issue? I'm working on a project which is bit old. The authentication part is handled on keycloak V21.1.2. I have updated both next-auth("@nuxtjs/auth-next": "5.0.0-1667386184.dfbbb54") and nuxt-axios ("@nuxtjs/axios": "^5.13.6",). I have updated the project's nuxt version from 2.14.0 to 2.17.3 too. Still not redirecting to the dashboard and just redirect to the login page and its looping between callback page and login page continuously. auth: {
}, Where its wrong in my code |
I'm using @nuxtjs/auth-next in my Nuxt application.
The application is configured using universal mode (or
ssr: true
sincemode: 'universal'
is obsolete)I have a super simple page called
pages/test.vue
, which looks likeI've also tested without Composition API, which looks like this:
It all works fine without SSR enabled, but when I enable it the
auth
middleware doesn't work and redirects me to the login page instead.I can verify that I'm authenticated since I can access the user via
$auth.user
, and I also have a valid non-expired token in LocalStorage.After digging a bit deeper into the
auth-next/dist/core/middleware.js
it seems likectx.$auth.$state.loggedIn
is false.Can someone please help me?
Version
5.0.0-1595976864.509d9d6
The text was updated successfully, but these errors were encountered: