auth-module: auth stuck at the callback URL — not storing Auth0 token [SPA mode]
EDIT All the testing links are not working anymore. Given the feedback and the PR made it seems the issue is solved so I took offline the demos I made for the various scenarios. I will check out the new PR too as soon as I can but given that the project maintainers already merged it to master I suppose it’s a go for production too.
Given the three tests I’ve done, I am making here a recap for clarity
- Mode SPA — example-auth0 repository https://github.com/nuxt-community/auth-module/issues/536#issue-568235358 Reproduction link: https://nuxt.federicod.dev/
Application stays stuck at the callback page, not storing the auth0 token, in the chance that this was an issue with the example-auth0 repo alone I’ve tested also the example build in the auth-module repo.
- Mode SPA — auth-module repository https://github.com/nuxt-community/auth-module/issues/536#issuecomment-589557690 Reproduction link: https://auth-test.federicod.dev/
Same as above, I now think that the issue resides indeed in the auth-module itself.
- Mode SSR (universal) — auth-module repository https://github.com/nuxt-community/auth-module/issues/536#issuecomment-589600857 Reproduction link: https://auth-test-ssr.federicod.dev/
After trying to build the SSR version of the example\demo application, and serving it with nuxt start I have confirmed that the auth-module either:
- doesn’t work at all in SPA mode;
- the build command with the SPA configuration breaks something
Mode SPA — example-auth0 repository
Version
Reproduction link
Steps to reproduce
git clone https://github.com/nuxt/example-auth0.git;- set Auth0
domainandclient_idintonuxt.config.js(I am not using the .env file as it seems to me that it doesn’t get embedded in the SPA after running npm run build) - set mode:
spa - nuxt build
- deploy the dist folder
- access the website and try to login with demo@demo.com; Demo1@23
- after the callback URL is opened, it stays stuck there
On a more complicated platform I am developing, some API calls that are made on the callback URL to populate a Vuex store all yields unauthorized error, meaning that the token doesn’t get stored at all.
When running example-auth0 and the application I am developing in development mode with npm run dev, everything works fine. So I suppose that something goes wrong only after running the build command.
What is expected ?
I expect the callback URL to be opened and the token received stored.
What is actually happening?
The SPA stays stuck at the callback URL and no token is stored.
Additional comments?
Webserver: Caddy Configuration:
nuxt.federicod.dev {
root /root/dev/example-auth0/dist
}
No errors are shown in the console.
<div align="right">This bug report is available on Nuxt community (#c500)</div>About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 8
- Comments: 26 (4 by maintainers)
After a whole day researching I stumbled upon these issues https://github.com/nuxt-community/auth-module/issues/299 and https://github.com/nuxt/nuxt.js/issues/5267.
The whole situation is still somewhat unclear to me, however I’ve tried to deploy the application in another way again Mode SSR (spa) — auth-module repository and the authentication flow worked as expected.
As referenced in the above mentioned issues it seems that static SPA mode is not supported at all by the auth-module (more specifically by its dynamic behaviour, so other libraries could be affected). What it is not explain at all in the documentation is that there are two possible ways to serve an SPA application:
mode: 'spa'nuxt buildandnuxt startmode: 'spa'nuxt buildand directly serving the dist folder as the document root with the webserver in useIn either case,
nuxt build examples\democreates two relevant folders:/distfolder in the project root;/example/demo/.nuxt;From the documentation on SPA one would assume that deploying only the
/distfolder is necessary, instead to have the authentication flow working properly it is needed to runnuxt start examples/demowhich serves the files from/example/demo/.nuxt.I am hella lot confused on the deployment process involved with Nuxt. I beg someone to explain what’s happening here.
I had trouble where callback url was configured for an oauth strategy but didn’t match $auth.options.redirect.callback so the middleware wasn’t extracting tokens from url fragment.
Hope this helps someone else.
Its not working for me either, netlify + auth0 mode spa, on local it’s working, deployed generated version not
I got similar issue fixed by changing token url
token: process.env.API_URL + '/auth/token'hope it helps someone.
complete auth config
Hi Fellow users
I have submitted a PR with a potential fix https://github.com/nuxt-community/auth-module/pull/586 (it fixed my login flow which has same issue), can some of you please try the fix and confirm if it fixes your issue too (or not).
Thanks Rajat Jindal
This is my solution to host on Zeit/Now and login using github:
now.json
functions/authorize.js
It’s just a serverless function who overrides
/_auth/oauth/github/authorizeand perform github authorization.The Nuxt community has a strong focus on SSR and sometimes the likes of us that need just a SPA can feel a little left behind…
Mode SPA — auth-module repository
To ensure it wasn’t an issue only on
example-auth0end I’ve also tried the following with theauth-modulerepo:Reproduction link https://auth-test.federicod.dev/
Steps to reproduce
git clone https://github.com/nuxt-community/auth-module.gitexamples/demo/nuxt.config.jswith my own Auth0 tenantnuxt build examples\demo --spaSame as above, when running auth-module development mode with
nuxt, everything works fine. So I suppose that something goes wrong only after running the build command.No errors are shown in console.
Thanks to r3dqu33n! I use Google OAuth2 provider in @nuxtjs/auth-next for authentication. Google makes callback to “/login” and the static site made with “nuxt generate” just does not have the page for it generated. I was already studying how to copy the module’s code for callback into my own page login.vue when I came across r3dqu33n’s code.
I authorized the callback url, no issues from google. But the auth module is completely non reactive when i arrive at the callback url with the tokens in the url. I have now added the following to my callback url page and it works.