Skip to content

Conversation

@PaulAsjes
Copy link
Contributor

When using middleware auth mode and Next.js server actions, it's possible to trigger a CORS issue. The edge case manifests itself when:

  1. User doesn't have a valid session (i.e. logged out in a separate tab)
  2. User triggers a server action in the now stale page
  3. CORS error surfaces in the browser console

The above happens because without a valid session and in middleware auth mode, the POST request to the server action is intercepted and a redirect to AuthKit is attempted, which triggers a CORS error.

The solution here is to wrap the server action call in a try/catch block so an error can displayed or the user redirected client side.

Also updates Next.js to its latest minor version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants