JavaScript: Sign in a user
A user can sign up either via email or OAuth.
If you provide email
without a password
, the user will be sent a magic link.
The magic link's destination URL is determined by the SITE_URL config variable. To change this, you can go to Authentication -> Settings on supabase.com/dashboard
Specifying a provider
will open the browser to the relevant login page.
Examples Sign in with email and password const \{ user, session, error \} = await supabase.auth.signIn(\{
email: 'example@email.com',
password: 'example-password',
\})
Sign in with magic link. const \{ user, session, error \} = await supabase.auth.signIn(\{
email: 'example@email.com'
\})
Sign in using third-party providers. const \{ user, session, error \} = await supabase.auth.signIn(\{
// provider can be 'github', 'google', 'gitlab', and more
provider: 'github'
\})
Sign in with phone and password const \{ user, session, error \} = await supabase.auth.signIn(\{
phone: '+13334445555',
password: 'some-password',
\})
Sign in using a third-party provider with redirect const \{ user, session, error \} = await supabase.auth.signIn(\{
provider: 'github'
\}, \{
redirectTo: 'https://example.com/welcome'
\})
Sign in with scopes const \{ user, session, error \} = await supabase.auth.signIn(\{
provider: 'github'
\}, \{
scopes: 'repo gist notifications'
\})
const oAuthToken = session.provider_token // use to access provider API
Sign in using a refresh token (e.g. in React Native). // An example using Expo's `AuthSession`
const redirectUri = AuthSession.makeRedirectUri(\{ useProxy: false \});
const provider = 'google';
AuthSession.startAsync(\{
authUrl: `https://MYSUPABASEAPP.supabase.co/auth/v1/authorize?provider=$\{provider\}&redirect_to=$\{redirectUri\}`,
returnUrl: redirectUri,
\}).then(async (response: any) => \{
if (!response) return;
const \{ user, session, error \} = await supabase.auth.signIn(\{
refreshToken: response.params?.refresh_token,
\});
\});