SupabaseS
Supabase2mo ago
Dexter

Auth in Page VS Auth in Middleware

Hello, I am currently exploring Auth using supabase and NextJs and I cannot figure out the correct "pattern" to go about auth. I do know how the latest supabase-ssr works (cookies, auth flow etc.) however I do not know what the best practices are.

From what I have gotten so far middleware intercepts every request, forwards the request to the supabase middleware and that simply checks if the user is authenticated. There you can redirect to login if not.

However I am not sure If I also need to check for an active session (supabase.getUser()) and redirect in each page I want protected or do it once in the middleware.

Am i understanding something wrong ?
Was this page helpful?