-
Notifications
You must be signed in to change notification settings - Fork 34
Added check if the Google OAuth account has e-mail verified flag #152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
397748d
Added check if the Google OAuth account has e-mail verified flag
tomassrnka 1c9d841
Fix: require explicit true for OAuth email verification
tomassrnka 708f7a5
Added nicer user error message
tomassrnka 558efe8
Simplified logic, we only check the first sign-up with OAuth
tomassrnka 64f1a03
Moved all error messages to user-messages.ts
tomassrnka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,3 +28,80 @@ export function encodedRedirect( | |
export function getUserProviders(user: User) { | ||
return user.app_metadata.providers as string[] | undefined | ||
} | ||
|
||
/** | ||
* Checks if a user's email is verified based on their OAuth provider's identity data. | ||
* Intended for use at signup when user has exactly one identity. | ||
* @param {User} user - The Supabase user object | ||
* @returns {{ verified: boolean, provider?: string, reason?: string }} - Verification status and details | ||
*/ | ||
export function isOAuthEmailVerified(user: User): { | ||
verified: boolean | ||
provider?: string | ||
reason?: string | ||
} { | ||
// Get the user's identities (OAuth providers they've signed in with) | ||
const identities = user.identities || [] | ||
|
||
if (identities.length === 0) { | ||
// Email/password user - consider verified if email_confirmed_at is set | ||
return { | ||
verified: !!user.email_confirmed_at, | ||
reason: user.email_confirmed_at | ||
? 'Email confirmed' | ||
: 'Email not confirmed', | ||
} | ||
} | ||
|
||
// Check the first identity (at signup, there's only one) | ||
const identity = identities[0] | ||
if (!identity) { | ||
return { verified: false, reason: 'No identity found' } | ||
} | ||
|
||
const provider = identity.provider | ||
const identityData = identity.identity_data | ||
|
||
if (!identityData) { | ||
return { | ||
verified: false, | ||
provider, | ||
reason: 'No identity data available', | ||
} | ||
} | ||
|
||
switch (provider) { | ||
case 'google': | ||
// Google provides email_verified field | ||
// Require explicit true - fail closed if undefined/null/false | ||
if (identityData.email_verified !== true) { | ||
return { | ||
verified: false, | ||
provider: 'google', | ||
reason: 'Google email not verified', | ||
} | ||
} | ||
break | ||
|
||
case 'github': | ||
// GitHub provides verified field (for email verification) | ||
// Note: GitHub returns the primary email's verification status | ||
// Require explicit true - fail closed if undefined/null/false | ||
if (identityData.verified !== true) { | ||
return { | ||
verified: false, | ||
provider: 'github', | ||
reason: 'GitHub email not verified', | ||
} | ||
} | ||
break | ||
|
||
// Add other providers as needed | ||
default: | ||
// For other OAuth providers, assume verified if they have an email | ||
break | ||
} | ||
|
||
// If we get here, the check passed | ||
return { verified: true, provider } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: OAuth Users Blocked by Incorrect New User Check
The
isNewUser
check, based ondata.user.identities?.length === 1
, incorrectly identifies existing users with a single OAuth identity as new. This subjects existing users to email verification checks, potentially blocking their sign-in if their OAuth provider's email verification status isn't met.