0
Challenge · 49Auth: Who Is Asking?

Server sessions: getClaims vs getUser vs getSession

Authused in ~95% of apps

Every Supabase + Next.js tutorial protects a page with roughly the same six lines: read the session, check if it exists, redirect if not. Three different Supabase methods can fill in that blank, they all compile, they all "work" in a five-minute demo — and one of them lets anyone who can edit a cookie in their browser's dev tools skip your login page entirely, on your server, in production. This is the single most-cited auth mistake of 2026, and it is invisible until someone forges a cookie on purpose.

Core idea. getSession() reads whatever is sitting in cookie storage and returns it as-is — no verification, so it is not proof of anything. getUser() sends that session's JWT to Supabase's Auth server, which checks it is real; always authentic, always a network round trip. getClaims() verifies the JWT's cryptographic signature locally, using a cached public key — authentic, and usually free of any network call at all. Server code that makes an authorization decision must use getClaims() by default, reach for getUser() only when it specifically needs the freshest possible state, and must never treat getSession() as proof of who is asking.
Playground, this isn't a screenshot
getSession()getUser()getClaims()
What it doesReads storage/cookies as-isAsks the Auth server to checkVerifies the signature locally
Network call?NoYes — every callUsually none (asymmetric keys)
Cryptographically verified?NoYesYes
Safe to authorize with, server-side?NeverYes — pay the round trip when freshness mattersYes — the 2026 default
↑ play a little first, then dig in