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.Your public anon key from the project settings.
Service Role Key (Private)
The service role key bypasses Row Level Security and should only be used in server environments.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.User’s email address.
User’s password (minimum 6 characters).
Optional user metadata.
Response
JWT access token for authenticated requests.
Token used to refresh the access token.
Time in seconds until the access token expires.
User information object.
Sign In
Sign in an existing user.User’s email address.
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 theAuthorization header:
Bearer token format:
Bearer <access_token>Refresh Token
Refresh an expired access token.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:OAuth provider name:
google, github, gitlab, azure, facebook, discord, etc.URL to redirect to after authentication.
Space-separated OAuth scopes to request.
Supported Providers
- GitHub
- GitLab
- Bitbucket
- Azure
- Discord
- Slack
- Spotify
- And more…
Magic Link Authentication
Send a passwordless sign-in link via email.User’s email address.
Phone Authentication
Authenticate users via SMS OTP.Send OTP
User’s phone number in E.164 format.
Verify OTP
User’s phone number.
6-digit OTP code.
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
New email address.
New password.
User metadata to update.
Security Best Practices
Always use HTTPS
Always use HTTPS
Never send API keys or tokens over unencrypted connections.
Implement RLS policies
Implement RLS policies
Always enable Row Level Security on your tables and create appropriate policies.
Rotate service role key
Rotate service role key
Regularly rotate your service role key if it’s been exposed.
Use short-lived tokens
Use short-lived tokens
Configure appropriate token expiration times in your auth settings.
Validate on the server
Validate on the server
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
