auth0-spa-js: Next js login @auth0/auth0-spa-js not working with loginWithRedirect while loginWithPopup works well
Problem
When trying to use
loginWithRedirectusing https://github.com/auth0/auth0-spa-js first time it successfully logging me in and takes to onboard page meanswindow.location.originafter login when I’m trying to login next time it just reloads the page and taking me back again and again while loginWithPopup works well.
What was the expected behavior?
Expected behaviour is after login it should take me to dashboard with token & user details.
Reproduction
npm install @auth0/auth0-spa-js- follow the steps as suggested here https://github.com/auth0/auth0-spa-js
Environment
- Version “@auth0/auth0-spa-js”: “^1.20.1”, used.
- Browsers Chrome & safari.
- Framework
next js( used this SDK also https://auth0.com/docs/quickstart/webapp/nextjs/01-login ) same behaviour for redirect login now using https://github.com/auth0/auth0-spa-js. its behaviour is also same
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 2
- Comments: 24 (9 by maintainers)
I don’t think we’ve changed anything specific in this area that would be causing your issue, but I’ve yet to deep-dive into it. Once I’ve had a chance to try and reproduce it this week, I’ll come back to you.
@tiwarivijay123 I’ve got some feedback on your code sample I can share tomorrow.
@TrueWill we also have an SDK built specially for Next.js in case that’s an even better fit: https://github.com/auth0/nextjs-auth0
Yeah ok thanks @stevehobbsdev I guess now you can close this issue
Here is more code to review @stevehobbsdev , any issues here please let us know…
@tiwarivijay123 in your code sample, you can’t simply await
loginWithRedirectand expect a result, as it will do a full-page redirect and state is lost. You need to callhandleRedirectCallbackwhen Auth0 redirects back to your application in order to get authentication results.I tried it’s older version as well https://github.com/auth0/auth0-spa-js/releases but nothing seem to work. after successfully login it just come to back with
this is code which I’m trying for

undefineduser detail and does nothing I’m using this version its latest but I tried older version as well but it is sameloginWithRedirectI just saw something similar - unsure if it’s the same bug or not.
We upgraded from version 1.10.0 to 1.20.1, so I would not expect any breaking changes (assuming people follow semver). I didn’t see anything impactful in the changelog.
But now when calling
loginWithRedirect(identical code other than the library version) and passing aredirect_uri, it’s redirecting to a different URL and resulting in a 404.Using more-or-less vanilla JS on this project (Backbone). Browser Chrome.