ยฉ 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabaseโ€ข4y agoโ€ข
24 replies
Sythic

Correct way to use a JWT on the server side to initialize a client as that user?

Most of the documentation seems to assume you're using supabase on both browser client and api side. We have a custom GQL api that needs to get the users JWT from Authorization header and create a client as that user for the duration of that request.

Attempting to use this in my request context (ApolloGQL server)
export const getClient = (token?: string): SupabaseClient => {
  return createClient(SUPABASE_API_URL, token || SUPABASE_ANON_TOKEN);
};
export const getClient = (token?: string): SupabaseClient => {
  return createClient(SUPABASE_API_URL, token || SUPABASE_ANON_TOKEN);
};


This doesn't seem to create me a client authorized as that user (token is the JWT from Authorization header)

supabase.auth.user()
supabase.auth.user()
is null but tells me I should use
auth.api.getUserByCookie()
auth.api.getUserByCookie()
to do this in the server context. But I'm not using a cookie or any type of session management
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

The right way to initialize a client using the `ssr` package?
SupabaseSSupabase / help-and-questions
3y ago
Server Side Requests from a Mobile App that uses Client side Auth
SupabaseSSupabase / help-and-questions
13mo ago
How to use JWT to authenticate user on a custom server?
SupabaseSSupabase / help-and-questions
4y ago
Best way to get authenticated user on client side
SupabaseSSupabase / help-and-questions
13mo ago