OAuth providers let users sign in using their Google or GitHub accounts. This makes login easy and secure without creating new passwords.
OAuth providers (Google, GitHub) in Supabase
supabase.auth.signInWithOAuth({ provider: 'google' })
supabase.auth.signInWithOAuth({ provider: 'github' })Use the provider name as a string: 'google' or 'github'.
This method opens a popup or redirects to the provider's login page.
await supabase.auth.signInWithOAuth({ provider: 'google' })
await supabase.auth.signInWithOAuth({ provider: 'github' })
await supabase.auth.signInWithOAuth({ provider: 'google', options: { redirectTo: 'https://yourapp.com/welcome' } })
This code creates a Supabase client and starts the Google OAuth login flow. If there is an error, it logs it. Otherwise, it logs that the login started.
import { createClient } from '@supabase/supabase-js' const supabaseUrl = 'https://xyzcompany.supabase.co' const supabaseKey = 'public-anonymous-key' const supabase = createClient(supabaseUrl, supabaseKey) async function signInWithGoogle() { const { data, error } = await supabase.auth.signInWithOAuth({ provider: 'google' }) if (error) { console.error('Error during Google sign-in:', error.message) } else { console.log('Google sign-in started:', data) } } signInWithGoogle()
Make sure to set up OAuth credentials in your Supabase project dashboard first.
Redirect URLs must match those configured in Google or GitHub developer settings.
OAuth login opens a popup or redirects the user to the provider's login page.
OAuth providers let users sign in with Google or GitHub accounts easily.
Use supabase.auth.signInWithOAuth({ provider: 'google' }) or 'github' to start login.
Set up credentials and redirect URLs in Supabase and provider dashboards before using.