Authentication & Authorization
Resolved
Example from the ReviewMyCodes team
Next.js + Supabase: user looks signed out after refreshing the page
Description
Sign-in works, but after a page refresh or after about an hour my server components think the user is signed out, even though the browser still has Supabase cookies.
— This is an example problem from the ReviewMyCodes team, showing how a good question looks. Real community questions appear alongside it.
Expected
The user stays signed in across refreshes until they sign out.
Actual
supabase.auth.getUser() returns null in server components after the access token expires.
Steps to reproduce
- Sign in
- Wait for the access token to expire (or refresh several times)
- Load a server-rendered page
Code
typescript
// app/dashboard/page.tsx
export default async function Dashboard() {
const supabase = await createClient();
const { data: { user } } = await supabase.auth.getUser();
if (!user) redirect("/login");
// ...
}