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

Next.js doesn't support auth redirects in middleware for server actions #50

Open
Daniel-Ash opened this issue Aug 21, 2024 · 2 comments
Labels
documentation Improvements or additions to documentation

Comments

@Daniel-Ash
Copy link

Daniel-Ash commented Aug 21, 2024

Improve documentation

Link

https://supabase.com/docs/guides/auth/server-side/nextjs

Describe the problem

Next.js will not follow middleware auth redirects in a server action. If a user's authentication is not valid (e.g. has expired), the server action returns a 307 but the user will not be redirected - can be very confusing to debug.

This only happens when the redirect comes from the middleware layer. Calling redirect() in the server action is fine.

See discussion here, where they advise to add an auth check to each server action:
vercel/next.js#64993

Auth docs recommends checking auth on each action.
https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations#authentication-and-authorization

Describe the improvement

Docs should say to skip POST requests in middleware and validate the user in each route.

@Daniel-Ash Daniel-Ash added the documentation Improvements or additions to documentation label Aug 21, 2024
@jkgatt
Copy link

jkgatt commented Aug 27, 2024

Same issue for example from Stripe Webhooks incoming.

@hf
Copy link
Collaborator

hf commented Aug 28, 2024

Oh wow!

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

No branches or pull requests

3 participants