Closed kenhuang1964 closed 4 months ago
I was using clerk for authentication with supabase but now I'm trying to switch to work os. Is there a way to access the user's token to work with supabase?
import { createClient } from "@supabase/supabase-js"; import { auth } from "@clerk/nextjs"; export default async function supabaseClient() { const { userId, getToken } = auth(); if (!userId) throw new Error("User not authenticated"); const accessToken = await getToken({ template: "supabase" }); const supabase = createClient( process.env.NEXT_PUBLIC_SUPABASE_URL ?? "", process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY ?? "", { global: { headers: { Authorization: `Bearer ${accessToken}` } }, } ); return supabase; }
I was using clerk for authentication with supabase but now I'm trying to switch to work os. Is there a way to access the user's token to work with supabase?