This code shows how Supabase Auth handles identity by signing up a user, signing them in, and then getting their current identity.
import { createClient } from '@supabase/supabase-js'
const supabaseUrl = 'https://xyzcompany.supabase.co'
const supabaseKey = 'public-anonymous-key'
const supabase = createClient(supabaseUrl, supabaseKey)
async function authFlow() {
// Sign up a new user
const { data: signUpData, error: signUpError } = await supabase.auth.signUp({
email: 'bob@example.com',
password: 'mypassword'
})
if (signUpError) {
console.log('Sign up error:', signUpError.message)
return
}
console.log('Sign up success:', signUpData.user.email)
// Sign in the user
const { data: signInData, error: signInError } = await supabase.auth.signInWithPassword({
email: 'bob@example.com',
password: 'mypassword'
})
if (signInError) {
console.log('Sign in error:', signInError.message)
return
}
console.log('Sign in success:', signInData.user.email)
// Get current user
const { data: { user: currentUser } } = await supabase.auth.getUser()
console.log('Current user:', currentUser.email)
}
authFlow()