Connection & Authentication
const { createClient } = require('@supabase/supabase-js')
Create a Supabase client
const supabase = createClient('https://YOUR_SUPABASE_URL.supabase.co', 'YOUR_SUPABASE_KEY')
Initialize Supabase client with URL and API key
User Management
const { data, error } = await supabase.auth.signUp({ email, password })
Sign up a new user
const { data, error } = await supabase.auth.signInWithPassword({ email, password })
Sign in an existing user with email/password
const { error } = await supabase.auth.signOut()
Sign out the current user
const { data: { user } } = await supabase.auth.getUser()
Get the currently logged in user
OAuth Authentication
const { data, error } = await supabase.auth.signInWithOAuth({ provider: 'google' })
Sign in with Google OAuth
const { data, error } = await supabase.auth.signInWithOAuth({ provider: 'github' })
Sign in with GitHub OAuth
const { data, error } = await supabase.auth.signInWithOAuth({ provider: 'facebook' })
Sign in with Facebook OAuth
Session Management
const { data: { session } } = await supabase.auth.getSession()
Get the current session
const { data, error } = await supabase.auth.refreshSession()
Refresh the current session
supabase.auth.onAuthStateChange((event, session) => {})
Listen for authentication state changes
Password Management
const { data, error } = await supabase.auth.resetPasswordForEmail(email)
Send password reset email
const { data, error } = await supabase.auth.updateUser({ password: newPassword })
Update user's password
User Data
const { data, error } = await supabase.auth.updateUser({ data: { custom_field: 'value' } })
Update user metadata
const { data: { user } } = await supabase.auth.getUser()
Get user metadata
JWT Management
const { data: { session } } = await supabase.auth.getSession()
Get JWT token from session
const jwt = session.access_token
Access the JWT token