mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 09:55:06 +03:00
Correct the code examples for the Clerk third-party auth docs: - Fix TypeScript error - Change RLS policy check to accept both [Clerk v1 and v2 JWTs](https://clerk.com/docs/backend-requests/resources/session-tokens) Pulled code samples from an example app that I've checked in to make maintenance and testing easier in the future.
17 lines
520 B
TypeScript
17 lines
520 B
TypeScript
import { useSession } from '@clerk/nextjs'
|
|
import { createClient } from '@supabase/supabase-js'
|
|
|
|
export function useSupabaseClient() {
|
|
const { session } = useSession()
|
|
const supabaseClient = createClient(
|
|
process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
|
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
|
|
{
|
|
// Session accessed from Clerk SDK, either as Clerk.session (vanilla
|
|
// JavaScript) or useSession (React)
|
|
accessToken: async () => session?.getToken() ?? null,
|
|
}
|
|
)
|
|
return supabaseClient
|
|
}
|