Error with auth0 vercel next.js login

I’ve had trouble with the user being callbacked to the home page and being logged in.
I’ve quadruple checked all the environment variable in the Vercel deployment, used all the right callback and logout URLs in the Application Settings, and it won’t work.

The callback URL is right b/c any other callback URL returns an error.
I am able to press login, go through the Universal Login Page, and enter my credentials. But when I press continue, I get redirected to an error page pointing to /api/auth/callback with the a code and state in the URL parameters

If I manually go back to the home page, I’m not logged in, but if I go to the Auth0 Users Page, it shows that: a). there was an account created if not already there and b). there was a login made by that user

My URLs are correct or else they would return a specified error page of the callback URL not being right, I’ve triple-checked my client secrets and generated secret, and I’ve replaced them tons of times, I’ve used the same custom domain in my environment variables and in the callback URLs, and I use the same AUTH0 issuer base URL.

By the way, the app’s authentication on the code side uses a pages w/out the app router, as that was what was there in the tutorial when I started out, and the standard handleAuth() in the [auth0].ts file in /api/auth in my code and it is exported. that is all the configuration I’ve used. And the _app.tsx is wrapped in the tags

All authentication works completely normally on the locally hosted server, but the problems arise during production as usual.

registered login:
image

image

im testing in production, and by default, it had preview and production selected in vercel
I am currently using a pages router for my app
I am getting no error log on vercel at /api/auth/callback
I get a call to /api/auth/login when logging in

my auth0 log also reflects a successful login with no error

nextjs version: Next.js v13.4.12

auth0 version: 9.5.0

here’s my error -just a generic error page after I press continue on my universal login page
there’s a code and state in the URL

I also noticed I get a an API read operation in my auth0 logs to get a client and the data seems normal but the application and connection are shown as N/A and I don’t know whether it’s relevant or not - does this show where it could be going wrong

finally, i noticed that this may not just be a callback problem, as when i add an redirect action, i get redirected to the action redirect page but to the same type of generic error page, telling me that there is some problem with how auth0 is processing the login and not just failing the callback but even the actions

one more small thing is that i do get a string of errors in my network tab and i did notice that the state from the /authorize/resume changes when it goes to /api/auth/callback

Is there any other apparent thing I’ve missed in trying to figure out what is wrong and does anything i say give an idea to what i need to fix?

since the login flow goes

user - > logs in - > auth0 auth server - > user data - > auth0 actions => id token & access token = > application

my guess is that if it can’t finish the action either, it might be problem with the authorization server, but it still registers as a successful login

Hey there @secomm !

You could double check if the auth0 config (specifically the auth0 domain and other app specific data) in your app on production refers to a right auth0 tenant. There are two similarly named Auth0 tenants you probably work with, one of them with a postfix “stage”.

Hope this helps, let us know!

hi @marcelina.barycka

my universal login page is working and its on the right auth0 issuer base URL with .us.auth0 at the end, and changing that makes the login page not work, so i’m not sure whether the problem is with the configured URL

the same goes for my custom domain - i have the right custom domain configured with vercel, in the vercel environment variables, and in the callback/logout URLs in my Auth0 application settings, and if i run a different URL, errors of the callback URL being wrong come up

i only have one production tenant with me that i am working in

i might be misunderstanding your question but i believe i am using the right auth0 URL pointing to the same tenant

do any of the other errors in my post and information there give any clue to what’s going wrong -i know it’s long but I’m not sure what’s happening so i gave as much information as possible

thank you so much once again

Hey there @secomm !

Happy to here the Auth0 Universal Login Page and the relevant flow function as expected.

Looking at the screenshoot you have shared, I would investigate it by researching the error message, which seems referring to the Domain Name System not able resolving a website’s URL into an IP address, making the web browser unable to reach it.

The error indicates that you have a typo - I would double check it.

Hope it helps, thanks!

thank you so much @marcelina.barycka !

i needed to include www. in all the env variables and the callback URLs

before i had tried this but i had only included it in the callback URLs and hadn’t changed the auth0_url to include www., so thank you so much, took me 2 months to figure this out

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.