Skip to main content
Supabase Auth is a complete authentication system that handles user sign-ups, logins, and session management. It’s built on top of PostgreSQL and integrates seamlessly with Row Level Security for authorization.

Architecture

Supabase Auth consists of four major layers:
  1. Client Layer: Your application code using Supabase SDKs or direct HTTP calls
  2. Kong API Gateway: Routes requests and validates JWTs
  3. Auth Service (GoTrue): Manages authentication logic and token issuance
  4. PostgreSQL Database: Stores user data in the auth schema
The Auth service is a fork of GoTrue, originally created by Netlify and enhanced by Supabase.

How Authentication Works

When a user signs in:
  1. Client sends credentials to the Auth service via the API gateway
  2. Auth service validates credentials against the database
  3. Upon success, Auth service issues a JWT (JSON Web Token)
  4. Client stores the JWT and includes it in subsequent requests
  5. Kong gateway validates the JWT on each request
  6. PostgreSQL uses the JWT to enforce Row Level Security policies

Authentication Methods

Supabase Auth supports multiple authentication methods:

Email and Password

The traditional username/password approach:
Passwordless authentication via email:

OAuth Providers

Supabase supports 20+ OAuth providers including:
  • Google
  • GitHub
  • Apple
  • Facebook
  • Twitter
  • Microsoft
  • Discord
  • And many more…

Phone Authentication

SMS-based authentication:

Anonymous Sign-In

Create temporary users without credentials:

User Management

User Object

The user object contains authentication data:

User Metadata

Store additional user information:

Profile Tables

Create a public profile table linked to auth.users:
Create profiles automatically with a trigger:

Session Management

Automatic Session Refresh

Supabase SDKs automatically refresh expired sessions:

Manual Session Management

Session Callbacks

Listen for auth state changes:

Multi-Factor Authentication (MFA)

Add an extra layer of security with TOTP-based MFA:

Server-Side Auth

Next.js (App Router)

API Routes

Authorization with RLS

Combine Auth with Row Level Security:
Access user info in policies:

Auth Hooks

Customize authentication flows with hooks:
  • Before User Created: Modify user data before creation
  • Send Email: Customize email sending
  • Send SMS: Customize SMS sending
  • Password Verification: Custom password validation
  • Custom Access Token: Add custom claims to JWTs
  • MFA Verification: Custom MFA logic
Example custom access token hook:

Security Best Practices

Use RLS

Always enforce authorization with Row Level Security policies.

Enable MFA

Require multi-factor authentication for sensitive operations.

Validate Emails

Enable email confirmation to verify user email addresses.

Rate Limiting

Configure rate limits to prevent abuse and brute force attacks.

Next Steps

Social Auth

Set up OAuth providers for social login

Server-Side Auth

Implement authentication in server components

Auth Hooks

Customize authentication flows with hooks

RLS Policies

Secure your data with Row Level Security