From cf62ce9dfa3d5a8f66b518ca0337fcb488371c5f Mon Sep 17 00:00:00 2001 From: Salakar Date: Tue, 25 Sep 2018 18:59:26 +0100 Subject: [PATCH] [auth][js] implement user.getIdTokenResult method + flow types --- src/modules/auth/User.js | 30 ++++++++++++++++-------------- src/modules/auth/types.js | 11 +++++++++++ 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/modules/auth/User.js b/src/modules/auth/User.js index 3188f6ed..637d06fd 100644 --- a/src/modules/auth/User.js +++ b/src/modules/auth/User.js @@ -13,6 +13,7 @@ import type { UserCredential, UserInfo, UserMetadata, + IdTokenResult, } from './types'; type UpdateProfile = { @@ -96,24 +97,25 @@ export default class User { } /** - * get the token of current user - * @return {Promise} + * Returns a JWT token used to identify the user to a Firebase service. + * + * @param forceRefresh boolean Force refresh regardless of token expiration. + * @return {Promise} */ getIdToken(forceRefresh: boolean = false): Promise { - return getNativeModule(this._auth).getToken(forceRefresh); + return getNativeModule(this._auth).getIdToken(forceRefresh); } - // /** - // * get the token of current user - // * @deprecated Deprecated getToken in favor of getIdToken. - // * @return {Promise} - // */ - // getToken(forceRefresh: boolean = false): Promise { - // console.warn( - // 'Deprecated firebase.User.prototype.getToken in favor of firebase.User.prototype.getIdToken.' - // ); - // return getNativeModule(this._auth).getToken(forceRefresh); - // } + /** + * Returns a IdTokenResult object which contains the ID token JWT string and other properties for getting + * data associated with the token and all the decoded payload claims. + * + * @param forceRefresh boolean Force refresh regardless of token expiration. + * @return {Promise} + */ + getIdTokenResult(forceRefresh: boolean = false): Promise { + return getNativeModule(this._auth).getIdTokenResult(forceRefresh); + } /** * @param credential diff --git a/src/modules/auth/types.js b/src/modules/auth/types.js index 64655509..30f4776b 100644 --- a/src/modules/auth/types.js +++ b/src/modules/auth/types.js @@ -3,6 +3,17 @@ */ import type User from './User'; +export type IdTokenResult = { + token: string, + authTime: string, + issuedAtTime: string, + expirationTime: string, + signInProvider: null | string, + claims: { + [key: string]: any, + }, +}; + export type ActionCodeInfo = { data: { email?: string,