Skip to content
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

state mismatch error occurring after logging out and logging back in #1749

Open
6 tasks done
sincraianul opened this issue May 20, 2024 · 2 comments
Open
6 tasks done

Comments

@sincraianul
Copy link

sincraianul commented May 20, 2024

Checklist

Description

A state mismatch error occurs if logging back in immediately after log out.

Reproduction

  1. Be logged in
  2. Log out (hit the /api/auth/logout endpoint)
  3. Be redirected back to the login page because of the middleware (shared in the "Additional context" section)
  4. Log in with credentials
  5. Be prompted to choose an organization (we use a multi-org flow)
  6. A 400 error is thrown (state mismatch) during the callback phase

Additional context

  1. We use a custom auth domain, but it doesn't seem to influence the issue

  2. We use the identifier-first flow

  3. We let the Universal Login prompt the user for an organization they want to use when logging in

  4. We use a catch-all middleware (which is why the user gets redirected to the login page immediately after logout):

    import { withMiddlewareAuthRequired } from "@auth0/nextjs-auth0/edge";
    
    export default withMiddlewareAuthRequired();
    
    export const config = {
      matcher: [
        /*
         * Match all request paths except for the ones starting with:
         * - api (API routes)
         * - _next/static (static files)
         * - _next/image (image optimization files)
         * - favicon.ico (favicon file)
         */
        "/((?!api|_next/static|_next/image|favicon.ico).*)",
      ],
    };
  5. HAR recording

  6. The issue only occurs if the user is already logged in

  7. The issue doesn't occur if the user navigates to the app URL manually after the error occurs. They are presented with the organization picker and the callback succeeds once they choose the org.

nextjs-auth0 version

3.5.0

Next.js version

14.0.4

Node.js version

20.9.0

@ybce
Copy link

ybce commented Aug 19, 2024

I'm running into the same issue here, did you manage to find a solution?

@ymonye
Copy link

ymonye commented Nov 10, 2024

Also curious to know if this was resolved, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants