Google Sign-In With Supabase in Next.js: Which Address Goes Where
Add Continue with Google to a Next.js and Supabase starter: follow the redirect chain, set up the Google Cloud consent screen and a web client, paste the client ID and secret into Supabase, and read the one server action behind the button.
What you will learn
- Trace a Google sign-in from the button through Supabase and Google and back to /auth/callback
- Set up a Google Cloud consent screen in testing mode with test users
- Create a web OAuth client with the right redirect URI and JavaScript origin
- Read the signInWithOAuth server action and the Google button that calls it
Before you start
- Email login with Supabase in Next.js
- A Google account
Our starter kit already signs people in with email and password (see the email login article). Now we add Google as one more way in. Three places change. The front end gets a Continue with Google button, Supabase gets the Google provider, and Google Cloud gets an OAuth client. Most of the confusion is about which address goes into which field, so let's start with the trip a sign-in takes.
How a Google sign-in travels
So there are two callbacks. Google sends the browser back to Supabase's callback URL, and that's what you register in Google Cloud as the redirect URI. Supabase then sends the browser to our /auth/callback, and that address has to be on Supabase's Redirect URLs list. The Google client ID and secret live in Supabase. Our front end never sees them.
Hand the front end to the agent first
The code is small, so let Claude Code work on it while you set up the dashboards. With Frontend as the working directory:
Role: You're a Next.js and Supabase developer.
Context: Our starter kit already has Supabase email and password login, and I'm turning on the Google provider in Supabase.
Task: Add a Continue with Google button to the login and sign-up pages, and connect it to Supabase's Google sign-in.
Format: Change the code, update sample env if a new value is needed, and list any dashboard steps I still have to do.
Supabase: switch on Google
Authentication → Sign in / Providers, scroll to Google, switch on Enable sign in with Google. It asks for the client IDs and the client secret. Both come from Google Cloud, so keep this tab open. At the bottom of the panel is the Callback URL (for OAuth). You'll need it in a minute.
Google Cloud: project and consent screen
- Open the Google Cloud console and create a fresh project for this app. With a personal account the parent is "no organisation", and that's fine.
- APIs and services → Credentials. Google asks you to configure the consent screen first. That's the page people see when they sign in: your app's name and who to contact.
- App name, and your user support email.
- Audience: External. Internal is only for users inside a Google Workspace organisation, so it isn't an option with a personal account. The app starts in testing mode, and only test users you add can sign in.
- Contact email, tick the user data policy, continue, create.
Under Audience, the publishing status is Testing. Don't click Publish app: that opens the app to any Google account, and Google may ask to verify it. Instead, click Add users and add the emails you'll test with. You can add up to one hundred test users while the app is in testing.
Google Cloud: the OAuth client
Clients → Create client:
| Field | Value |
|---|---|
| Application type | Web application |
| Name | Anything, it's only for you |
| Authorised JavaScript origins | http://localhost:3000 (address and port, no path) |
| Authorised redirect URIs | The Supabase callback URL you copied |
If you add an origin row and leave it empty, Google shows "Invalid origin: URI must not be empty". Google also notes that these settings can take from five minutes to a few hours to apply, so if sign-in fails right away, give it a little time.
Click create, and Google shows the client ID and the client secret. Copy both now: once you close the dialog, you can't view the secret again. Treat it like a password. It never goes in your code or a screenshot.
Back in Supabase, paste the client ID and the secret into the Google provider and save. You get "Successfully updated settings", and Google shows as enabled.
What the agent changed
Its summary ends with the dashboard steps. The redirect URL http://localhost:3000/auth/callback is already on Supabase's list from the email login step, and Google sign-in comes back to the same callback. The env values stay the same: no new variables, because the Google credentials live in Supabase.
One new server action in actions.ts:
export async function signInWithGoogle(formData: FormData) {
const redirectTo = String(formData.get("redirectTo") ?? "/dashboard") || "/dashboard";
const origin = await getOrigin();
const supabase = await createClient();
const { data, error } = await supabase.auth.signInWithOAuth({
provider: "google",
options: {
redirectTo: `${origin}/auth/callback?next=${encodeURIComponent(redirectTo)}`,
},
});
if (error) {
redirect(`/login?error=${encodeURIComponent(error.message)}`);
}
// `data.url` is Google's consent screen. Send the browser there.
redirect(data.url);
}
When we ran it, data.url was Supabase's authorize address, with provider google and our callback as the redirect. From there Supabase sends the browser on to Google. The callback route already swaps the code for a session, so it needed no change.
The button, in components/auth/google-button.tsx, is a small form whose action is that function:
function GoogleSubmit() {
const { pending } = useFormStatus();
return (
<Button type="submit" variant="secondary" disabled={pending} className="h-11 w-full text-[15px]">
{pending ? <Loader2 className="size-4 animate-spin" /> : <GoogleIcon />}
Continue with Google
</Button>
);
}
export function GoogleButton({ redirectTo = "/dashboard" }: { redirectTo?: string }) {
return (
<div className="space-y-5">
<form action={signInWithGoogle}>
<input type="hidden" name="redirectTo" value={redirectTo} />
<GoogleSubmit />
</form>
{/* "or" divider below */}
</div>
);
}
A hidden input carries redirectTo. useFormStatus sets pending while the action runs, so the button is disabled and shows a spinner. One line in login-form.tsx places the button above the email field, and the sign-up form gets it too.
Try the sign-in
npm run dev, open localhost:3000, sign out, and click Continue with Google. Google opens its sign-in page for our app. Pick a test user, and you're back on the dashboard with Sign out in the user menu.
In Supabase under Users, the new row has provider Google and provider type social. The account from the email sign-up now shows email and Google, because the lecture also signed in with Google using that same address, and Supabase linked both to one user.
Common mistakes
- Putting your app's callback in Google's redirect URI. Google returns to Supabase, so that field takes Supabase's callback URL.
- A path on the JavaScript origin. Use just
http://localhost:3000. - Signing in with an account that isn't a test user. In testing mode only listed accounts get in.
- Closing the dialog before copying the secret. You can't view it again.
- Putting the client secret in
.env. It belongs in the Supabase provider settings.
Quick recap
| Where | What you set |
|---|---|
| Google Cloud | Consent screen (External, testing, test users), web client, origin http://localhost:3000, redirect URI = Supabase callback |
| Supabase | Google provider on, client ID and secret pasted, /auth/callback on Redirect URLs |
| Front end | signInWithOAuth({ provider: "google" }) action, a button that posts to it |
The other providers in Supabase's list follow the same pattern. Next, we protect the password login from bots: hCaptcha on the login page.
StudyEasy AI Community
Learn AI engineering, share what you build, and connect with other learners.
Free resources: lesson files, notebooks and code
Ask questions and join engineering discussions
Meet real people learning and building with AI
Related course on Udemy
The Python Architect Masterclass: Full Stack to AI Engineer
Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)Related posts
Server State With TanStack Query: One Key, One Request, One Cache
Three components need the same list of books. Fetch it by hand and you get three requests; ask TanStack Query for one key and you get one. With real request counts, retries and a quiet refetch on tab focus.
Mutations and Optimistic Updates in TanStack Query: Change Data, Then Tell the Cache
Add a book with useMutation and let invalidateQueries refetch the list, then make delete instant: snapshot, remove the row in 3 ms, roll back on a 404 and refetch the truth in onSettled.
Generate TypeScript Types, Query Hooks and Zod From an OpenAPI Spec With Orval
Let the API's OpenAPI spec write your React client: Orval turns /v3/api-docs into TypeScript types, useGetBooks and a Zod schema, and a renamed field becomes error TS2339 at BookList.tsx line 26.
A Mock Backend in the Browser With Mock Service Worker, Generated From the Spec
Build the React screen before the API exists: Orval writes MSW handlers and faker data from the spec, a service worker answers GET /api/books inside the browser, and npm run dev:real switches back to the real server.
