© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•13mo ago•
3 replies
Matffin

Correct way to get 'access_token' / user session in server components

Hi,
I setup role-based access control according to the RBAC docs.
The custom auth hook is including the user role in the access token JWT.
My project is using NextJS with React server components. Supabase-js is setup according to the docs as well.

I can access and decode the JWT with 'jwt-decode' on the client like outlined in the docs.
What would be the correct way to access the access_token or user session in a React server component?
The docs state that using
supabase.auth.getSession()
supabase.auth.getSession()
is unsafe on the server.

Should I store the JWT in a separate cookie once the user signs in and decode with the JWT secret on the server?

My use case is protecting certain routes based on the user role in a layout file.

Thanks!
Custom Claims & Role-based Access Control (RBAC) | Supabase Docs
Use Auth Hooks to add custom claims for managing role-based access control.
Custom Claims & Role-based Access Control (RBAC) | Supabase Docs
Setting up Server-Side Auth for Next.js | Supabase Docs
Setting up Server-Side Auth for Next.js | Supabase Docs
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
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Any way to access the access_token from session on server ? (Am using Sveltekit)
SupabaseSSupabase / help-and-questions
4y ago
How to get user or session info on server side?
SupabaseSSupabase / help-and-questions
4y ago
Where to get access token for CICD?
SupabaseSSupabase / help-and-questions
4y ago
auth-helpers-sveltekit best way to access session
SupabaseSSupabase / help-and-questions
4y ago