You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am running into an invalid_state error while testing organizations/invitations with 4.0.0-beta.13. I can tell what's happening, but I don't know why it's happening so could use some help resolving.
My current knowledge of what's happening:
When I click on the link in the invitation I am taken to the /auth/login route with the organization and invitation query param set.
I can tell that auth0 middleware does a couple of things when processing the /auth/login request. It returns a Next.redirect response to the /authorize endpoint on the auth0 server with the correct query params (client id, state, organizationId, invitationId, etc.). I can also tell the the transaction state is included in a set-cookie header with the same corresponding state value with the __txn prefix.
The middleware redirects to Auth0 Universal login page with the organization and invitation param set and the UI correctly prompts me to accept the invitation.
I accept the invitation and I am redirected back to the /auth/callback route handler with the same state query param from step 2.
This all looks like it's working correctly, except the auth0 middleware now returns an invalid_state error. After debugging I can tell the request cookies in the /auth/callback request do NOT include the transaction state cookie that was set in step 2! So the auth0 middleware cannot find the corresponding state and throw an error.
I'm not entirely clear why this behavior is only happening when trying to accept an invitation. Performing a regular login appears to persist the transaction state cookie correctly.
Reproduction
Send an invitation in the Auth0 console
Click on the link in the invitation email
See you are redirected to Universal Login page and prompted to accept the invitation
Log in to accept the invite and see you are redirected back to the app
Upon redirect, see that you encounter an invalid_state error from the auth0 middleware
Additional context
No response
nextjs-auth0 version
4.0.0-beta.13
Next.js version
15.1.0
Node.js version
20.9.0
The text was updated successfully, but these errors were encountered:
Ok so discovered that this must just be an issue with using the direct local IP address 127.0.0.1 in the login URL. When I use localhost:3000 in the URL it looks like the cookies are set correctly. I suspect this is some quirk with Chrome in how it handles cookies on redirects.
The reason I was using 127.0.0.1 instead of localhost was because the Auth0 UI does not allow me to set the login URI to localhost (or use HTTP instead of HTTPS for local development). Here is the error I get:
And then when I try to use HTTPS:
This is the URI used in the invitation email, so it's inconvenient and confusing to need to manually update the link from HTTPS -> HTTP and 127.0.0.1 -> localhost when accepting the invitation during local dev.
Checklist
Description
I am running into an invalid_state error while testing organizations/invitations with 4.0.0-beta.13. I can tell what's happening, but I don't know why it's happening so could use some help resolving.
My current knowledge of what's happening:
/auth/login
route with theorganization
andinvitation
query param set./auth/login
request. It returns a Next.redirect response to the/authorize
endpoint on the auth0 server with the correct query params (client id, state, organizationId, invitationId, etc.). I can also tell the the transaction state is included in aset-cookie
header with the same corresponding state value with the__txn
prefix./auth/callback
route handler with the same state query param from step 2.invalid_state
error. After debugging I can tell the request cookies in the/auth/callback
request do NOT include the transaction state cookie that was set in step 2! So the auth0 middleware cannot find the corresponding state and throw an error.I'm not entirely clear why this behavior is only happening when trying to accept an invitation. Performing a regular login appears to persist the transaction state cookie correctly.
Reproduction
Additional context
No response
nextjs-auth0 version
4.0.0-beta.13
Next.js version
15.1.0
Node.js version
20.9.0
The text was updated successfully, but these errors were encountered: