How to Add Google Sign-In to a Next.js App With Supabase

You want someone to open your app, choose Google, and get on with what they came to do. If they already have an account, they should find their existing work when they return.
Google checks which Google account the person is using. Supabase, which already handles your app's accounts, connects that identity to an app account. Your app must then recognize them and open the right page. We'll add that flow to your existing Next.js app, the framework used to build its pages and features.
In my dog-training app, Doogle, I use Google sign-in alongside six-digit email codes. See Doogle (opens in a new tab).
Keep your existing email option. Google gives people another familiar way in. Your AI can handle the connected settings and code; you'll give it access and try the finished experience with real accounts.
Before you start
Your app should already let people create an account, sign in, reload a private page, and sign out. If that foundation is missing, use the account-setup guide linked above first.
Open the existing app in your AI coding tool. Sign in to the Google and Supabase accounts that manage it. Authorize the tool's access when needed; handle your own passwords and account-verification questions.
Start where you test changes. Have AI check its connection to Supabase first: an app running on your computer can still share account settings with the public app.
Have a Google account that is new to your app ready. Also have an existing email user with a Google account at that same verified address, if possible. You'll check both joining and returning to existing work.
Step 01Have your AI check the setup
Have AI find the existing account code, the page people should reach after sign-in, and its available Google and Supabase setup tools.
There are two return trips. Google sends the person back to Supabase. Supabase then sends them back to your app. A return address may be called a callback or redirect URL in the settings. The two services need different addresses because they do different parts of the job.
Your AI should replace these examples with your actual addresses. Supabase's Google setup (opens in a new tab) documents the first return; its app return settings (opens in a new tab) cover the second.
The last example assumes your app uses /auth/callback. AI should inspect or create the actual return handler and use its address. For an active custom Supabase address, use the return address Supabase currently shows.
When the app runs locally but uses hosted Supabase, Google's return address stays with hosted Supabase. Let the actual connection decide.
This inspection prompt produces actual addresses and identifies missing access before settings change. The later prompts can then refer to one agreed setup.
Step 02Set up your app in Google
Google keeps the app's identity, audience, and sign-in connections inside a Google project. Google's publishing rules (opens in a new tab) require separate projects for testing and the public app, also called production. Two connections inside one project are not enough. Reuse a valid setup if you have one.
Google's sign-in settings live in Google Auth Platform (opens in a new tab), under Audience, Branding, Data Access, and Clients. Google's client settings (opens in a new tab) explain the connection fields. Your AI can operate the browser you authorized. If it cannot, it should give you the exact remaining fields and resume once you finish.
For a public app, choose External as the audience. Internal limits access to the relevant Google organization. Request only the person's basic identity: their account identifier, email address, and profile. Google names these permissions openid, email, and profile. Signing in does not require access to their Gmail, Drive, or Calendar.
Google's Testing rules (opens in a new tab) have a useful exception for those basic identity permissions alone. Users do not have to be on a test-user list, and the usual testing warning and seven-day authorization expiry do not apply. Extra permissions change that. Your AI needs to check what the app actually asks Google for, and work or school accounts can still have their own restrictions.
Supply your real app name, support contact, homepage, and the policy links Google asks for. Google's branding process (opens in a new tab) separates checking the name and logo from publishing them; publishing the app is another setting. Have AI report each state without promising review timing.
Have AI fill in the app information and basic permissions through your authorized Google browser. This prompt keeps test and public settings separate and asks you for missing facts or access.
The website connection is called a Web application client. Put the app's base address in Authorized JavaScript origins, with no page path. The full Google-to-Supabase return address belongs in Authorized redirect URIs. These are the two Google fields from your map.
Google gives the connection an identifier, called a client ID, and a private password, called a client secret. Keep the secret out of chat and your app's browser code. New secrets are shown when created, so have your AI save it privately if its tools support that. Otherwise, enter it yourself in Supabase in the next step.
Step 03Connect Google to Supabase
Supabase's Google provider settings hold the client ID and secret. An authorized connection for changing account settings is called the Supabase Management API. Your AI can use it or the signed-in dashboard, following Supabase's provider setup (opens in a new tab).
A connected Supabase tool may lack controls for account settings. Have AI check. If it cannot handle the secret privately, it should open the Google provider's credential fields for you to enter it.
Supabase also needs to know where people can return inside your app. The default app address is called Site URL. The allowed return addresses (opens in a new tab) are listed under Redirect URLs. The app's full return address belongs on that list; the code in the next step must use the same value.
Keep the addresses your existing email sign-in needs. If testing shares Supabase with the public app, preserve the public Site URL and settle that shared arrangement before changing provider credentials.
This prompt connects Google to Supabase and saves the app's return address. AI reads the current settings first, keeping the values your existing email sign-in needs.
Step 04Add Google sign-in to your app
Put Google beside email on the screens people use to join and return. Follow Google's button guidance (opens in a new tab) for its label, logo, and spacing. Use that presentation with the Supabase account system you already have.
The button starts sign-in; your app must finish the return. Supabase sends back a temporary code. The app exchanges it for its signed-in state, called a session, so it can recognize the person after returning and on a reload.
Your existing email return may do a different job. Have AI inspect it before adding Google's return handling. Supabase's server-side setup (opens in a new tab) explains how the browser and server share the signed-in state. Your AI should use your installed versions and existing account helpers.
I would start with the app's existing landing page after sign-in. Remembering the task someone was trying to open is useful too, provided the app checks that the destination is allowed.
While Google opens, show that the button is working and prevent repeated clicks. If someone cancels, let them choose Google again or use email. A Google cancellation should not tell them to request another email code.
This prompt has AI build the button and return handling using your existing account features. It also covers the waiting and retry behavior people see.
Step 05Test new and returning users
Have AI run the checks it can operate while you choose Google accounts and complete Google's sign-in questions. The account picker is only the start; check what happens back inside your app.
For an existing email user, use the same verified email address in Google. Supabase's automatic identity linking (opens in a new tab) can attach that Google identity to the existing user. This does not merge arbitrary accounts with different addresses. Accounts using a company's separate shared sign-in system, called SAML, are excluded. Your app's own profile and saved work still need checking.
Use this short sequence to cover joining, returning, and leaving:
- Start signed out. Choose Google with an account that is new to your app. Confirm that you reach the intended page as the right person.
- Complete any first-visit setup and save a little test work. Reload and check that the app still recognizes you.
- Sign out of the app. Confirm that a private page requires sign-in again. Return with the same Google account and find your test work.
- Try the existing email user through Google with that same verified address. Check the expected account and saved work.
- Cancel a Google attempt where the screen allows it. Check that you can retry or choose email without a stuck loading button.
- Use the existing email option again and confirm that it still reaches the expected app account.
App sign-out leaves your Google account signed in, so Google may recognize you quickly next time. Adding Google also does not create a password for an account that never had one. Check the email method your app actually supports.
This prompt has AI run checks and guide your real-account steps. It asks for a specific repair and retest after failures, and keeps anything you could not try marked as untested.
Google rejects a return address
For redirect_uri_mismatch, have AI compare the address sent to Google with Authorized redirect URIs in the client Supabase actually uses. It should be the full Google-to-Supabase address.
Check the https part, hostname, path, capitalization, and trailing slash. Correct it, allow time for Google's settings to take effect, and start a fresh attempt. Supabase's app-return list controls a different step.
Your app opens signed out
For the wrong page, inspect the app return address and Supabase's allowed list. For the right page but no signed-in account, have AI check the code exchange and saved sign-in state.
If it works until you reload, have AI inspect the browser and server account helpers and cookie handling. Supabase's return-handling guide (opens in a new tab) explains how that state is shared.
Google will not let this account continue
Have AI read Google's message and check the audience and actual permissions. An organization-only app or a work account's restrictions can change who is allowed in.
Adding everyone as a test user may not help. Check whether the basic-identity exception applies. If the app asks for more access, have AI explain why before you grant it.
Step 06Check Google sign-in on the published app
Publish the reviewed change through your normal process. Its Google connection belongs in the separate public Google project. Have AI confirm the public app's Supabase project and full return address.
Check Google's public-app settings, product information, and any unfinished review. Use secure https addresses. Google's production guidance (opens in a new tab) keeps developer-only addresses out of the public connection.
Open the address your users will visit. Choose Google, return to the right account, reload, and sign out. Repeat on a phone. If users arrive through a browser inside another app, test that entry separately; the desktop result cannot tell you how it behaves.
Have AI inspect the published app and list the checks that still need your device or account. Try those yourself. The person should get back to their app and their work.
This prompt carries the tested change through publishing and checks the public address. It keeps the Google projects separate and identifies real phone checks that need you.
You may see a Supabase address on Google's screen. Once sign-in works, you can replace the visible Supabase address with your own domain using the separate guide linked here. Treat that as the next refinement; finish the working Google sign-in first.
Still having trouble?
Pull me into your project with @Vlad, your virtual co-founder. Or, if you'd rather work with the real me, set up a call.
Summary
The finished experience is straightforward: choose Google, return to the app, and keep using the expected account. Google checks the person, Supabase handles the account, and your app finishes the return.
Let your AI handle the settings, code, and repeatable checks. Use your own accounts and phone to see what people will actually experience. Once that works, spend your attention on what they came into the app to do.
Sources
13 references- Supabase: Sign in with Google (opens in a new tab)supabase.com
- Google: Manage OAuth Clients (opens in a new tab)support.google.com
- Google: Manage App Audience (opens in a new tab)support.google.com
- Google: Manage OAuth App Branding (opens in a new tab)support.google.com
- Google: Comply with OAuth 2.0 policies (opens in a new tab)developers.google.com
- Supabase: Redirect URLs (opens in a new tab)supabase.com
- Supabase: Creating a client for server-side rendering (opens in a new tab)supabase.com
- Supabase: Advanced server-side guide (opens in a new tab)supabase.com
Show 5 more references
- Supabase: Identity Linking (opens in a new tab)supabase.com
- Google: Sign in with Google Branding Guidelines (opens in a new tab)developers.google.com
- Supabase: Update auth service config (opens in a new tab)supabase.com
- Supabase: Get auth service config (opens in a new tab)supabase.com
- OWASP: Unvalidated Redirects and Forwards Cheat Sheet (opens in a new tab)cheatsheetseries.owasp.org
Choose your next move
