0
0
Supabasecloud~5 mins

Why Supabase Auth handles identity

Choose your learning style9 modes available
Introduction

Supabase Auth manages who you are in an app. It keeps your login safe and simple.

When you want users to sign up and log in easily.
When you need to keep user data private and secure.
When you want to track who is using your app.
When you want to connect user actions to their identity.
When you want to avoid building your own login system.
Syntax
Supabase
supabase.auth.signUp({ email: 'user@example.com', password: 'password123' })
supabase.auth.signInWithPassword({ email: 'user@example.com', password: 'password123' })
const { data: { user } } = await supabase.auth.getUser()
Use signUp to create a new user account.
Use signInWithPassword to log in an existing user and get their identity.
Examples
Creates a new user with email and password.
Supabase
const { data, error } = await supabase.auth.signUp({ email: 'alice@example.com', password: 'secret' })
Logs in the user and returns their identity info.
Supabase
const { data, error } = await supabase.auth.signInWithPassword({ email: 'alice@example.com', password: 'secret' })
Gets the current logged-in user's identity details.
Supabase
const { data: { user } } = await supabase.auth.getUser()
Sample Program

This code shows how Supabase Auth handles identity by signing up a user, signing them in, and then getting their current identity.

Supabase
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()
OutputSuccess
Important Notes

Supabase Auth stores user identity securely so you don't have to.

It supports many login methods like email, social logins, and magic links.

Always keep your Supabase keys safe and never expose secret keys in frontend code.

Summary

Supabase Auth manages user identity simply and securely.

It helps apps know who is using them without extra work.

Use it to add login and user tracking easily.