Skip to main content
Version: v2 RC

signInWithOAuth()

Log in an existing user via a third-party provider.

const { data, error } = await supabase.auth.signInWithOAuth({
provider: 'github'
})

Parameters

  • SignInWithOAuthCredentialsrequiredobject

    No description provided.

      Properties
    • providerrequiredProvider

      One of the providers supported by GoTrue.

    • optionsoptionalobject

      No description provided.

        Properties
      • queryParamsoptionalobject

        An object of query params

      • redirectTooptionalstring

        A URL to send the user to after they are confirmed.

      • scopesoptionalstring

        A space-separated list of scopes granted to the OAuth application.

Notes

  • This method is used for signing in using a third-party provider.
  • Supabase supports many different third-party providers.

Examples

Sign in using a third-party provider

const { data, error } = await supabase.auth.signInWithOAuth({
provider: 'github'
})

Sign in using a third-party provider with redirect

When the third-party provider successfully authenticates the user, the provider will redirect the user to the URL specified in the redirectTo parameter. This parameter defaults to the SITE_URL. It does not redirect the user immediately after invoking this method. You can modify the SITE_URL or add additional redirect urls in your project.

const { data, error } = await supabase.auth.signInWithOAuth({
provider: 'github'
options: {
redirectTo: 'https://example.com/welcome'
}
}

Sign in with scopes

If you need additional data from an OAuth provider, you can include a space-separated list of scopes in your request to get back an OAuth provider token. You may also need to specify the scopes in the provider's OAuth app settings, depending on the provider. The list of scopes will be documented by the third-party provider you are using and specifying scopes will enable you to use the OAuth provider token to call additional APIs supported by the third-party provider to get more information.

const { data, error } = await supabase.auth.signInWithOAuth({
provider: 'github'
options: {
scopes: 'repo gist notifications'
}
})
const oAuthToken = data.session.provider_token // use to access provider API