Version: Next

User Management

Introduction

Supabase makes it easy to manage your users.

When a user signs up, Supabase assigns them a unique ID. You can reference this ID anywhere in your database. For example, you might create a profiles table references the user using a user_id field.

Supabase provides the routes to sign up, login, log out, and manage users in your apps and websites.

Sign up

New user.
const {
body: { user },
} = await supabase.auth.signup(
'someone@email.com',
'password'
)

Allow your users to sign up and create a new account.

After they have signed up, all interactions using the Supabase JS client will be performed as "that user".

Log in

Existing user.
const {
body: { user },
} = await supabase.auth.login(
'someone@email.com',
'password'
)

If an account is created, users can login to your app.

After they have logged in, all interactions using the Supabase JS client will be performed as "that user".

User data

Get the logged in user.
const user = await supabase.auth.user()

Get the JSON data for the logged in user.

Log out

Clear the user's session.
await supabase.auth.logout()

After calling log out, all interactions using the Supabase JS client will be "anonymous".

Error handling

Shows how to parse errors returned from the server.
try {
const res = await supabase
.auth
.login('someone@email.com', 'password')
} catch (error) {
if (error.response === undefined) {
// No response from server
} else {
const server_response = error.response
// Here you can further process the response ..
}
if (error.status === undefined) {
// No HTTP status code
} else {
const http_code = error.status
// Further processing ..
}
}

Third Party Logins

You can enable Google OAuth by navigating to Authentication > Settings > Google Login and inputting your Client ID and Secret.

To fetch these you need to:

  1. Start a project on Google Cloud then navigate to https://console.developers.google.com/apis/credentials?project=<your-project-id>
  2. Select Create Credentials > OAuth Client ID
  3. Select Application Type: Web Application
  4. Enter Authorized Redirect URI: http://<your-project>.supabase.co/auth/v1/callback

You can now test your integration by navigating to: https://<your-project>.supabase.co/auth/v1/authorize?provider=google. This is where you should send your users to authenticate.

After authenticating you should be redirected to <your-site-url>/#access_token=xyzabc&expires_in=3600&refresh_token=abcdef&token_type=bearer. This site url can be updated on the Supabase dashboard at Authorization > Settings.

The user will now appear in your database in the auth.users table.

You can now use the access_token in the url above in an Authorize header like: Authorization: Bearer xyzabc when making requests to your REST or Realtime APIs in order to authenticate as that user. If using supabase-js then you can set the accessToken on the client:

Sets the accessToken inside supabase-js
supabase.auth.saveSession(
access_token, // from callback URL
refresh_token, // from callback URL
Math.round(Date.now() / 1000) + expires_in, // current time + seconds from callback URL
null // currentUser not present yet
)

If you require any help with these steps please contact alpha@supabase.io