Skip to content
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

[passport-google-oauth20] Update email_verified type and override passport.Profile provider type #69338

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 5 additions & 10 deletions types/passport-google-oauth20/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export interface StrategyOptionsWithRequest extends _StrategyOptionsBase {

export interface Profile extends passport.Profile {
profileUrl: string;

provider: "google";
/**
* An identifier for the user, unique among all Google accounts and
* never reused. A Google account can have multiple email addresses at
Expand All @@ -51,8 +51,7 @@ export interface Profile extends passport.Profile {
* Ex: `"10769150350006150715113082367"`
*/
id: string;
emails?: Array<{ value: string; verified: "true" | "false" }>;

emails?: Array<{ value: string; verified: boolean }>;
_raw: string;
/**
* ID Token payload, adhering to Google's implementation of the OpenID
Expand All @@ -69,7 +68,7 @@ export interface Profile extends passport.Profile {
* "at_hash": "HK6E_P6Dh8Y93mRNtsDB1Q",
* "hd": "example.com",
* "email": "jsmith@example.com",
* "email_verified": "true",
* "email_verified": true,
* "iat": 1353601026,
* "exp": 1353604926,
* "nonce": "0394852-3190485-2490358"
Expand Down Expand Up @@ -147,12 +146,8 @@ export interface Profile extends passport.Profile {
email?: string;
/**
* True if the user's e-mail address has been verified; otherwise false.
*
* _Note:_ This comes as the string "true" or "false", not as a boolean!
*
* Ex: `"true"`
*/
email_verified?: "true" | "false";
email_verified?: boolean;
/**
* The user's given name(s) or first name(s). Might be provided when a name
* claim is present.
Expand Down Expand Up @@ -283,7 +278,7 @@ declare module "passport" {
InitializeRet = express.Handler,
AuthenticateRet = any,
AuthorizeRet = AuthenticateRet,
AuthorizeOptions = AuthenticateOptions,
AuthorizeOptions = passport.AuthenticateOptions,
> {
authenticate(
strategy: "google",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ export function mapGoogleProfileToUser(profile: google.Profile): UserProfile {
// @ts-expect-error - because emails[0] may not exist.
console.log(profile.emails?.[0].verified);

// @ts-expect-error - because emails[0].verified will be 'true' or 'false'.
console.log(profile.emails?.[0]?.verified === true);
// @ts-expect-error - because emails[0].verified will be true or false.
console.log(profile.emails[0].verified);

// @ts-expect-error
console.log(profile._json.email.toLowerCase());

return {
googleUserId: profile.id,
email: email ? email.value : null,
emailVerified: email ? email.verified === "true" : null,
emailVerified: email ? email.verified : null,
familyName: profile.name?.familyName || null,
givenName: profile.name?.givenName || null,
name: profile.name ? profile.displayName : null,
Expand Down