How to Add Google Login to Your App (the Right Way)
How Sign in with Google works, working code with Auth.js for Next.js, and the two details that prevent duplicate accounts.
Muhammad Usman
April 15, 2026 · 2 min read
Nobody wants another password. Sign in with Google removes signup friction, and users trust it. Here is how it works and what adding it actually involves.
How it works in one paragraph
Your app sends the user to Google, Google confirms who they are, and returns a signed proof of identity to your app. You never see their password; Google vouches for them. This is the OAuth flow, and every login provider works the same way.
The setup with Auth.js (Next.js)
First create OAuth credentials in Google Cloud Console (client ID and secret, plus your callback URL). Then the code is genuinely short:
// auth.ts
import NextAuth from 'next-auth'
import Google from 'next-auth/providers/google'
export const { handlers, auth, signIn, signOut } = NextAuth({
providers: [Google],
})
// app/api/auth/[...nextauth]/route.ts
import { handlers } from '@/auth'
export const { GET, POST } = handlers// A login button in a server action
import { signIn } from '@/auth'
export default function LoginPage() {
return (
<form action={async () => { 'use server'; await signIn('google') }}>
<button>Sign in with Google</button>
</form>
)
}On other stacks the same job is done by Supabase Auth or Firebase (enable the Google provider in the dashboard) and Laravel Socialite (composer require laravel/socialite).
The two details everyone misses
- Account linking: if someone signed up by email earlier and now uses Google with the same address, link the accounts instead of creating a duplicate user
- Keep one non-Google path: some corporate users cannot use Google services, offer email login too
What Google gives you
Basic sign-in shares name, email, and profile photo, and it is free for normal applications. Anything beyond that, like reading contacts or Gmail, requires extra permission scopes and a verification review by Google.
Frequently asked questions
Is Google login free?+
Yes for normal applications. Google charges nothing for standard sign-in usage.
Can I get the user’s Gmail contacts or emails?+
Only with extra permission scopes and Google’s verification review. Basic login only shares name, email, and profile photo.
What happens if the user revokes access?+
The next login fails and your app should treat them as signed out. Their account and data in your database remain until you delete them.