Prompt

How do I build an account linking flow for email and Google login?

Technology / Identity & Access3 observationsLast seen Nov 7, 2026

Latest observation

Nov 7, 2026OpenAI APIWeb search: off

A solid account-linking flow for email/password + Google login should do two things well:

  1. Prevent duplicate accounts for the same person.
  2. Avoid accidentally merging two different people’s accounts.

Here’s a practical way to design it.


1) Decide your account model

Use one user record and multiple identities/auth methods attached to it.

Example tables:

  • users

    • id
    • email
    • name
    • created_at
    • status
  • auth_identities

    • id
    • user_id
    • provider (email, google)
    • provider_subject (google sub, or email login identifier)
    • email
    • email_verified
    • created_at

This lets one user have:

  • password/email login
  • Google login
  • later, maybe Apple, GitHub, etc.

2) Define your matching rules

Safe automatic linking

Only auto-link when you have strong proof it’s the same person.

Good candidates:

  • The user is already signed in and explicitly connects Google from settings.
  • Google returns a verified email that exactly matches the signed-in account’s email.

Unsafe automatic linking

Avoid auto-linking just because:

  • the email strings match but email is unverified
  • the provider returns a name matching an existing user
  • the user is not signed in and you only see the same email

3) Recommended user flows

Flow A: New user signs up with email

  1. User enters email/password.
  2. Create users row.
  3. Create auth_identities row for email.
  4. Send verification email.
  5. Mark email verified once confirmed.

Flow B: New user continues with Google

  1. User clicks “Continue with Google”.
  2. OAuth completes.
  3. Check Google sub:
    • If already linked, log them in.
    • If not linked, check verified email against existing users.
  4. If no match, create new user + Google identity.
  5. If a match exists, decide whether to:
    • auto-link, or
    • ask the user to sign in first and then link

4) Best practice for linking email and Google

Preferred UX

If a user is already logged in and wants to add Google:

  • Go to Account Settings → Connected Accounts
  • Click Link Google
  • Complete Google OAuth
  • If Google email matches the current account email and is verified, attach the identity

This is the cleanest approach.

If user starts with Google, then later email/password

  • Create account from Google first
  • Later allow them to set a password
  • Or allow them to add email/password as a second credential

5) Handle the “same email” case carefully

Suppose a user signs in with Google and Google says:

  • email = alice@example.com
  • email_verified = true

And you already have a user with email alice@example.com.

You have two reasonable options:

Option 1: Auto-link if email is verified

Pros:

  • smooth UX Cons:
  • if your system allows unverified email accounts or multiple people share access to inbox, there’s some risk

Option 2: Require the user to prove ownership first

Example:

  • “We found an account with this email. Please sign in with your existing method to link Google.” Pros:
  • safer Cons:
  • slightly more friction

For most apps, Option 2 is safest unless your verification is strong and your risk is low.


6) Avoid account takeover

Never do this:

  • User logs in with Google
  • Google email matches an existing user email
  • You instantly attach Google to that account without verification

This can be risky if:

  • the existing account email isn’t verified
  • someone else controls that Google account
  • emails were reused/shared

Safer pattern:

  • If already logged in, allow linking.
  • If not logged in, treat the Google identity as a separate login unless you can verify ownership via email confirmation or a recovery flow.

7) Suggested login/linking decision tree

When Google OAuth succeeds:

  1. Find identity by provider + subject

    • If found → log into linked user
  2. Else if user is currently logged in:

    • Link Google identity to current user
    • If Google email conflicts with current user email, warn and require confirmation
  3. Else if Google email matches an existing user and email is verified:

    • Show “We found an existing account. Sign in to link it.”
    • Ask for password/email login or another proof step
  4. Else:

    • Create new user + Google identity

8) What to store for Google

Store:

  • provider = google
  • provider_subject = google_user_id (sub claim from ID token)
  • email
  • email_verified
  • access_token / refresh_token only if you need them to call Google APIs

Important:

  • Use Google sub as the stable external ID, not email.
  • Email can change; sub is the real identity.

9) What to store for email login

For email/password:

  • store password hash
  • store email verification status
  • optionally create an auth_identity row for email

If you allow “magic link” email login instead of password, that can also be an identity provider of its own.


10) Example pseudocode

async function handleGoogleLogin(googleProfile, currentUser = null) {
  const { sub, email, email_verified } = googleProfile;

  const existingIdentity = await db.auth_identities.findOne({
    provider: 'google',
    provider_subject: sub
  });

  if (existingIdentity) {
    return login(existingIdentity.user_id);
  }

  if (currentUser) {
    await db.auth_identities.insert({
      user_id: currentUser.id,
      provider: 'google',
      provider_subject: sub,
      email,
      email_verified
    });
    return login(currentUser.id);
  }

  const existingUser = await db.users.findOne({ email });

  if (existingUser && email_verified) {
    // safer: prompt user to sign in first or confirm link
    return {
      action: 'link_required',
      message: 'An account already exists with this email. Please sign in to link Google.'
    };
  }

  const user = await db.users.insert({ email });
  await db.auth_identities.insert({
    user_id: user.id,
    provider: 'google',
    provider_subject: sub,
    email,
    email_verified
  });

  return login(user.id);
}

11) Recommended UX copy

Helpful messages:

  • “Continue with Google”
  • “Link Google account”
  • “We found an account with this email. Please sign in to connect Google.”
  • “This Google account is already linked to another profile.”

12) Edge cases to plan for

  • User changes email on Google
  • User deletes one login method and still needs another
  • User has multiple Google accounts
  • Existing account uses unverified email
  • Duplicate accounts already exist and need merge
  • Refresh token revocation
  • Account recovery if one provider is lost

13) Best practice summary

If you want the safest, simplest pattern:

  • Use a single user record with multiple linked identities
  • Match Google by sub, not email
  • Allow linking only when:
    • the user is already authenticated, or
    • the user proves ownership of the existing account
  • Use email verification before any automatic merge
  • Never auto-merge solely based on email string

If you want, I can also give you:

  1. a database schema,
  2. a full flowchart, or
  3. example code for Node.js / Next.js / Django / Firebase / Auth0 / Supabase.

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (3 observations for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.