Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supabase and Clerk Migration Guide #419

Open
armansoltanidev opened this issue Jan 25, 2025 · 0 comments
Open

Supabase and Clerk Migration Guide #419

armansoltanidev opened this issue Jan 25, 2025 · 0 comments
Labels
question Further information is requested

Comments

@armansoltanidev
Copy link

Based on the supabase and clerk docs for creating user_id column where i cant copy this code to weok?

`import { useSession, useUser } from '@clerk/nextjs'
import { createClient } from '@supabase/supabase-js'

export default function Home() {
// The useSession() hook will be used to get the Clerk session object
const { session } = useSession()

// Create a custom supabase client that injects the Clerk Supabase token into the request headers
function createClerkSupabaseClient() {
  return createClient(
    process.env.NEXT_PUBLIC_SUPABASE_URL!,
    process.env.NEXT_PUBLIC_SUPABASE_KEY!,
    {
      global: {
        // Get the custom Supabase token from Clerk
        fetch: async (url, options = {}) => {
	        // The Clerk `session` object has the getToken() method      
          const clerkToken = await session?.getToken({
	          // Pass the name of the JWT template you created in the Clerk Dashboard
	          // For this tutorial, you named it 'supabase'
            template: 'supabase',
          })
          
          // Insert the Clerk Supabase token into the headers
	        const headers = new Headers(options?.headers)
          headers.set('Authorization', `Bearer ${clerkToken}`)
          
          // Call the default fetch
          return fetch(url, {
            ...options,
            headers,
          })
        },
      },
    },
  )
}

//... The rest of the code is removed for brevity

}
`
guide link: https://supabase.com/partners/integrations/clerk

@haydenbleasel haydenbleasel added the question Further information is requested label Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants