← All posts
·6 min read·GuardLayer

"Error getting user email from external provider"

SupabaseAuthOAuthRLS

"Error getting user email from external provider" is a 500 from Supabase Auth: the OAuth sign-in worked, but the provider (Discord, Facebook, X, Notion, Google Workspace and others) returned no email address, and that provider isn't set to allow email-less users. Fix it by granting the email permission on the provider side. If you switch on "Allow users without an email" instead, make sure nothing in your app or RLS uses the email as an identity check.

What does "Error getting user email from external provider" mean?

It means Supabase Auth got a user profile back from the provider with no email in it. The check is four lines in internal/api/external.go in supabase/auth:

if len(userData.Emails) == 0 && !emailOptional {
    return apierrors.NewInternalServerError("Error getting user email from external provider")
}

Because it's an OAuth callback, the error usually arrives in the redirect URL rather than as a JSON body. supabase/supabase#22726, a Notion login, shows the shape:

error=server_error&error_code=500&error_description=Error+getting+user+email+from+external+provider

If you got here from a game launcher, a Discord bot or a "Sign-in failed" screen in someone else's app, the fix isn't on your side. That app uses Supabase, and its developer needs to change the settings below.

Why does the provider return no email?

Supabase already asks for an email scope by default: email for Discord, Google and Facebook, user:email for GitHub. So when the email is missing, it's almost always a permission on the provider's side, or an account that has no email to give.

  • Notion: the integration needs the "Read user information including email addresses" capability. That's what a Supabase maintainer asked the reporter to check in #22726.
  • X / Twitter: the app needs "Request email from users" turned on in the X developer portal. Without it, X leaves the email out of the profile Supabase requests.
  • Google Workspace: Supabase's troubleshooting note, "Google Auth fails for some users", says some Workspace setups need the email scope requested explicitly. The fix it gives is to pass scopes: 'https://www.googleapis.com/auth/userinfo.email' to signInWithOAuth.
  • GitHub: Supabase reads /user/emails, so private emails still come through for OAuth Apps. A GitHub App needs the "Email addresses" read permission for that endpoint to return anything.
  • Facebook and Discord: some accounts simply have no confirmed email, typically ones registered with a phone number. No setting fixes those; you either refuse them or allow email-less sign-in.

Check the provider first. It fixes the error for everyone who has an email, without changing what an account looks like in your database.

What does "Allow users without an email" do?

It's a per-provider toggle in the dashboard (Authentication → Sign In / Providers), described in Studio as: "Allows the user to successfully authenticate when the provider does not return an email address." With it on, the check above is skipped and the sign-in completes.

The account then looks different from every other account you have. auth.users.email is NULL. The access token still carries an email claim, but it's an empty string, because the claim is declared as a plain string in supabase/auth's token struct. No confirmation email is sent, because there's nowhere to send it.

That's fine for an app that identifies users by auth.uid() and nothing else. It's a problem for anything that treats the email as proof of who someone is.

The access check that this exposes

Email is a tempting identity key: "staff are anyone at @acme.com", "the invitee is whoever has this address", "same email means same person". The quick version checks it straight from the JWT, and because the email claim on its own feels weak, adds the provider's "verified" flag:

-- Staff dashboard: anyone signed in with a verified @acme.com address.
create policy "staff can read all tickets" on public.tickets
  for select to authenticated
  using (
    (auth.jwt() ->> 'email') like '%@acme.com'
    and (auth.jwt() -> 'user_metadata' ->> 'email_verified')::boolean
  );
guardlayer scan · supabase/migrations/20261117000000_staff_tickets.sqlLive engine output
Check failed
75/100 · B
  • Criticalsupabase/migrations/20261117000000_staff_tickets.sql:6

    RLS policy trusts user-editable metadata

    Never read user_metadata in a policy. Use app_metadata / raw_app_meta_data, which the user cannot write — or better, keep the role/tenant in a table your server controls and join against it, e.g. USING (EXISTS (SELECT 1 FROM public.memberships m WHERE m.user_id = auth.uid() AND m.org_id = org_id)).

The email_verified half is the hole. Supabase copies the provider's profile into user_metadata, and user_metadata is writable by the signed-in user through supabase.auth.updateUser({ data: { ... } }). The flag the policy trusts is one the user can set themselves. We go through which fields a user can write in user_metadata vs app_metadata.

The email half is weaker than it looks too. The value is whatever the provider asserted. Supabase marks Facebook, X and Notion emails as verified without the provider reporting it (the Notion provider's source comments that Notion "dosen't provide data on if email is verified"). And once email-less sign-in is on, some of your users have an empty string where you expected an address. Code that compares user.email across tables, matches invites by email, or merges accounts by email now has to handle "" and NULL correctly. That kind of edge case is how policies fail open without throwing an error.

How do I fix it safely?

  1. Fix the provider permission first (the list above). It's the actual cause for most users.
  2. Turn on "Allow users without an email" only if you'll handle those users: no email-based allowlists, no "send a receipt to user.email" without a NULL check, no account merging by email.
  3. Base access on auth.uid() and data you control. Keep staff and tenant membership in a table, or in app_metadata, which only server-side code can write:
create policy "staff can read all tickets" on public.tickets
  for select to authenticated
  using (
    exists (select 1 from public.staff s where s.user_id = (select auth.uid()))
  );
  1. If you must gate on email (an invite flow, say), compare against the confirmed auth.users.email in a security definer function or on the server, and reject empty values explicitly.

What GuardLayer catches

The policy above fires supabase/rls-policy-user-metadata, a critical finding, because it reads user_metadata in an access decision. The same rule catches is_admin, role and tenant_id checks against user_metadata.

It doesn't flag the email half: auth.jwt() ->> 'email' in a policy is sometimes legitimate, so there's no rule for it. GuardLayer also can't see your provider settings or the dashboard toggle, because it reads your repo, not your project config.

Quick self-check

# Policies and code that make access decisions from email or user_metadata
grep -rnE "jwt\(\) *->>? *'email'|auth\.email\(\)|user_metadata" supabase/migrations
grep -rnE "user\.email|user_metadata\.email_verified" --include=*.ts --include=*.tsx app lib

Then count email-less accounts if you've enabled the toggle:

select count(*) from auth.users where email is null;

FAQ

How do I fix "Error getting user email from external provider" with Discord? Supabase already requests Discord's email scope, so the most likely cause is an account with no email on file. Either ask the user to add an email to their Discord account, or enable "Allow users without an email" for Discord and handle those accounts.

Is it safe to enable "Allow users without an email" in Supabase? Yes, if your app identifies users only by auth.uid(). It's unsafe if any RLS policy, invite flow or account-linking logic treats the email as identity, because those users have a NULL email and an empty email claim.

Why is the email claim empty in the Supabase JWT? Because the user signed in through a provider that returned no email, with email-less sign-in enabled. The claim is always present in the token and is an empty string when there's no email.

Can I trust email_verified in Supabase user_metadata? No. user_metadata is writable by the user, so email_verified there is just a value they can change. Don't use it in RLS policies or server-side checks.

Check your Supabase Auth settings and tables, free

Connect your Supabase project read-only. GuardLayer checks your Auth settings (leaked passwords, email confirmation, secure email change, token rotation, CAPTCHA, MFA) and your RLS, policies and grants, and says how to fix each problem. It never reads your rows and can't change anything.

Check my Supabase project

Prefer to check code instead? Scan your repo, no signup.

Keep reading