© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•4y ago•
11 replies
mazondo

Nextjs auth-helpers with middleware and magiclinks

I'm working on getting the official auth-helpers library working with NextJS and magiclinks, but hitting an issue. When the user is redirected back to the app, it'll authenticate with supabase and then return them to their original destination. Unfortunately, the session isn't set by the time it hits the middleware, so it'll push them back to the login page and then immediately authenticate them client-side on that page.

How can I get the middleware to recognize that the user is now authenticated after clicking on an emailed magic link?

Here's an example of how the middleware is configured. I don't have the email check, but the rest is the same: https://supabase.com/docs/guides/auth/auth-helpers/nextjs#auth-with-nextjs-middleware
Supabase Auth with Next.js
Supabase Auth with Next.js
Authentication helpers for Next.js API routes, middleware, and SSR.
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

nextjs auth wihtout helpers
SupabaseSSupabase / help-and-questions
4y ago
Struggles auth-helpers-nextjs
SupabaseSSupabase / help-and-questions
4y ago
Error building nextjs project with auth-helpers
SupabaseSSupabase / help-and-questions
4y ago
NextJS auth helpers - invalid flow state
SupabaseSSupabase / help-and-questions
3y ago