Authentication with Google in NextJS and Supabase
Before you start, make sure you have created Terms of Service and Privacy Policy pages. You will need to add these links when you set up Google Auth.
Set up a Google Search Console and add your domain to it. Verifying your domain will speed up the process of getting your app approved by Google.
Configuring Authentication in Google Cloud
- Go to the Google Cloud and create a new project if you don't have one already.
- Go to OAuth consent screen in Google Cloud to create a new consent screen.
- [OAuth consent screen] Set up the consent screen settings
- User Type: External
- Application name/logo: anything you want
- Add your website URL, privacy policy and terms of service URLs
- Add your domain as an authorized domain
- Add your email address
-
[Scopes] Add the following scopes to Your non-sensitive scopes:
.../auth/userinfo.email
.../auth/userinfo.profile
-
[Test users] section
- Add your email address as a test user
-
[Summary] section
- Check if everything is correct. If yes, click
Back to Dashboard
button.
- Check if everything is correct. If yes, click
- Go to Credentials and click
Create Credentials
to create a new OAuth Client ID.- Application type: Web application
- Name: anything you want
- Authorized JavaScript origins: leave empty
- Authorized redirect URIs: add
http://localhost:54321/auth/v1/callback
for local development andhttps://<project-id>.supabase.co/auth/v1/callback
- Click
Create
button - Save Client ID and Client Secret for later
Whenever you are ready with your app, return to the OAuth consent screen and click Publish App button. This will start the process of getting your app approved by Google. If it shows Prepare for verification button, go through the steps required.
Google will email you asking about the status of your app. Reply to this email.
Usually, it took me a couple of days to get my app approved by Google. But it can take longer if you use more sensitive scopes.
Configuring Authentication in Local Supabase
- In SupaLaunch, open config file
/supabase/config.toml
. - Find the following section, add your Google Client ID and Client Secret:
[auth.external.google]
enabled = true
client_id = ""
secret = ""
- Run
supabase stop
andsupabase start
to restart Supabase. - Now you should be able to login with Google while using your local Supabase.
Configuring Authentication in Production Supabase
Turn on authentication with Google in Supabase:
- In supabase.com, go Authentication -> Providers.
- Turn on Google Auth.
- Add your Google Client ID and Client Secret.
- Click Save.
Now Google Authentication should work in production with your test user. Once Google approves your app, it will work for all users.