Skip to main content

Overview

Supabase REST API supports multiple authentication methods to secure your endpoints. Authentication is handled through API keys and JSON Web Tokens (JWTs).

API Keys

Supabase provides two types of API keys:

Anon Key (Public)

The anon key is safe to use in browser and mobile applications. It respects Row Level Security (RLS) policies.
string
required
Your public anon key from the project settings.
The anon key should only be used with proper RLS policies in place. Never expose the service role key in client applications.

Service Role Key (Private)

The service role key bypasses Row Level Security and should only be used in server environments.
string
required
Your service role key from the project settings.
Never expose the service role key in client-side code, version control, or public repositories. It has full access to your database.

User Authentication

Sign Up

Create a new user account.
string
required
User’s email address.
string
required
User’s password (minimum 6 characters).
object
Optional user metadata.

Response

string
JWT access token for authenticated requests.
string
Token used to refresh the access token.
number
Time in seconds until the access token expires.
object
User information object.

Sign In

Sign in an existing user.
string
required
User’s email address.
string
required
User’s password.

Response

Returns the same structure as sign up with access token and user data.

Using the Access Token

Once you have an access token, include it in the Authorization header:
string
required
Bearer token format: Bearer <access_token>

Refresh Token

Refresh an expired access token.
string
required
The refresh token from the sign in response.

Sign Out

Invalidate the current session.

OAuth Providers

Initiate OAuth Flow

Redirect users to an OAuth provider:
string
required
OAuth provider name: google, github, gitlab, azure, facebook, discord, etc.
string
URL to redirect to after authentication.
string
Space-separated OAuth scopes to request.

Supported Providers

  • Google
  • GitHub
  • GitLab
  • Bitbucket
  • Azure
  • Facebook
  • Twitter
  • Discord
  • Slack
  • Spotify
  • LinkedIn
  • And more…
Send a passwordless sign-in link via email.
string
required
User’s email address.
object

Phone Authentication

Authenticate users via SMS OTP.

Send OTP

string
required
User’s phone number in E.164 format.

Verify OTP

string
required
User’s phone number.
string
required
6-digit OTP code.
string
required
Verification type: sms or phone_change.

Row Level Security (RLS)

Row Level Security works seamlessly with JWT authentication. The user’s JWT claims are available in PostgreSQL policies.

Example RLS Policy

Accessing JWT Claims

Access user claims in your policies:

Session Management

Get Current User

Update User

string
New email address.
string
New password.
object
User metadata to update.

Security Best Practices

Never send API keys or tokens over unencrypted connections.
Always enable Row Level Security on your tables and create appropriate policies.
Regularly rotate your service role key if it’s been exposed.
Configure appropriate token expiration times in your auth settings.
Never trust client-side validation alone. Always validate on the server with RLS.

Next Steps

Database Operations

Perform CRUD operations with authentication

Row Level Security

Learn about RLS policies