-
Notifications
You must be signed in to change notification settings - Fork 955
Description
[REQUIRED] Describe your environment
- Operating System version: macOS Monterey 12.1
- Browser version: Google Chrome 100.0.4896.127
- Firebase SDK version: 9.6.10
- Firebase Product: auth
[REQUIRED] Describe the problem
Steps to reproduce:
I've been using firebase v8, and yesterday I migrated v8 to v9.
With firebase v8, I used to get the userId below code.
user.getIdTokenResult().then(({ token, signInProvider, claims })=>{
const info = claims.firebase;
const [id] = info?.identities[signInProvider || ''];
consoel.log('Here is my id', id);
});
but after upgrading to v9, I get a type error
Property 'identities' does not exist on type '{ sign_in_provider?: string | undefined; sign_in_second_factor?: string | undefined; }'.
For testing, I signed up using Twitter, and I got a ParsedToken
.
and I printed that token on the console.
{
aud: "####",
auth_time: 123456,
exp: 123456,
firebase: {
identities: { twitter.com: ["ID"] },
sign_in_provider: "twitter.com",
},
iat: 123456,
...
}
identities
is existed.
but there are no identities
props in @firebase/auth/dist/auth-public.d.ts
/**
* Interface representing a parsed ID token.
*
* @privateRemarks TODO(avolkovi): consolidate with parsed_token in implementation.
*
* @public
*/
export declare interface ParsedToken {
/** Expiration time of the token. */
'exp'?: string;
/** UID of the user. */
'sub'?: string;
/** Time at which authentication was performed. */
'auth_time'?: string;
/** Issuance time of the token. */
'iat'?: string;
/** Firebase specific claims, containing the provider(s) used to authenticate the user. */
'firebase'?: {
'sign_in_provider'?: string;
'sign_in_second_factor'?: string;
};
/** Map of any additional custom claims. */
[key: string]: string | object | undefined;
}
I think it should be updated like this.
export declare interface ParsedToken {
/* ... */
'iat'?: string;
/** Firebase specific claims, containing the provider(s) used to authenticate the user. */
'firebase'?: {
identities: {
[key: string]: Array<IdTypeOfSomething>
};
'sign_in_provider'?: string;
'sign_in_second_factor'?: string;
};
/** Map of any additional custom claims. */
[key: string]: string | object | undefined;
}
I compare v8 to v9, and I've found why it happened.
In version 9
export declare interface IdTokenResult {
/**
* The authentication time formatted as a UTC string.
*
* @remarks
* This is the time the user authenticated (signed in) and not the time the token was refreshed.
*/
authTime: string;
/** The ID token expiration time formatted as a UTC string. */
expirationTime: string;
/** The ID token issuance time formatted as a UTC string. */
issuedAtTime: string;
/**
* The sign-in provider through which the ID token was obtained (anonymous, custom, phone,
* password, etc).
*
* @remarks
* Note, this does not map to provider IDs.
*/
signInProvider: string | null;
/**
* The type of second factor associated with this session, provided the user was multi-factor
* authenticated (eg. phone, etc).
*/
signInSecondFactor: string | null;
/** The Firebase Auth ID token JWT string. */
token: string;
/**
* The entire payload claims of the ID token including the standard reserved claims as well as
* the custom claims.
*/
claims: ParsedToken;
}
claims
defined as ParsedToken
in v9,
but v8 is
interface IdTokenResult {
/* ... */
claims: {
[key: string]: any;
};
}