diff --git a/README.md b/README.md index b9b1a712..8a81f53c 100644 --- a/README.md +++ b/README.md @@ -479,6 +479,18 @@ The Firebase user's email address, or null if the user has no email address. Whether the user's email address is verified. +**phoneNumber** - `String|null` + +The Firebase user's phone number, or null if the user has no phone number. + +**displayName** - `String|null` + +The Firebase user's display name, or null if the user has no display name. + +**photoURL** - `String|null` + +The Firebase user's photo URL, or null if the user has no photo URL. + **claims** - `Object` - _Added in v0.13.0-alpha.2_ Any [custom Firebase claims](https://firebase.google.com/docs/auth/admin/custom-claims#set_and_validate_custom_user_claims_via_the_admin_sdk). diff --git a/index.d.ts b/index.d.ts index 95aa2f82..8c49333a 100644 --- a/index.d.ts +++ b/index.d.ts @@ -22,6 +22,9 @@ export interface AuthUser { id: string | null email: string | null emailVerified: boolean + phoneNumber: string | null + displayName: string | null + photoURL: string | null claims: Record getIdToken: () => Promise clientInitialized: boolean diff --git a/src/__tests__/createAuthUser.test.js b/src/__tests__/createAuthUser.test.js index 2e9238a1..2d0970fe 100644 --- a/src/__tests__/createAuthUser.test.js +++ b/src/__tests__/createAuthUser.test.js @@ -21,6 +21,9 @@ describe('createAuthUser: basic tests', () => { clientInitialized: false, email: null, emailVerified: false, + phoneNumber: null, + displayName: null, + photoURL: null, getIdToken: expect.any(Function), id: null, firebaseUser: null, @@ -121,6 +124,9 @@ describe('createAuthUser: firebaseUserClientSDK', () => { id: 'abc-123', email: 'abc@example.com', emailVerified: true, + phoneNumber: '+1800-123-4567', + displayName: 'Abc Cdf', + photoURL: 'https://abc.googleusercontent.com/cdf/profile_photo.png', clientInitialized: false, getIdToken: expect.any(Function), firebaseUser: firebaseUserJSSDK, @@ -149,6 +155,9 @@ describe('createAuthUser: firebaseUserClientSDK', () => { id: 'abc-123', email: 'abc@example.com', emailVerified: true, + phoneNumber: '+1800-123-4567', + displayName: 'Abc Cdf', + photoURL: 'https://abc.googleusercontent.com/cdf/profile_photo.png', clientInitialized: false, getIdToken: expect.any(Function), firebaseUser: firebaseUserJSSDK, @@ -197,6 +206,9 @@ describe('createAuthUser: firebaseUserClientSDK', () => { claims: {}, email: 'abc@example.com', emailVerified: true, + phoneNumber: '+1800-123-4567', + displayName: 'Abc Cdf', + photoURL: 'https://abc.googleusercontent.com/cdf/profile_photo.png', clientInitialized: false, _token: null, }) @@ -234,6 +246,9 @@ describe('createAuthUser: firebaseUserAdminSDK', () => { id: 'def-456', email: 'def@example.com', emailVerified: true, + phoneNumber: '+1800-234-5678', + displayName: 'Def Ghi', + photoURL: 'https://def.googleusercontent.com/ghi/profile_photo.png', clientInitialized: false, getIdToken: expect.any(Function), firebaseUser: null, @@ -255,6 +270,9 @@ describe('createAuthUser: firebaseUserAdminSDK', () => { id: 'def-456', email: 'def@example.com', emailVerified: true, + phoneNumber: '+1800-234-5678', + displayName: 'Def Ghi', + photoURL: 'https://def.googleusercontent.com/ghi/profile_photo.png', clientInitialized: false, getIdToken: expect.any(Function), firebaseUser: null, @@ -314,6 +332,9 @@ describe('createAuthUser: firebaseUserAdminSDK', () => { claims: {}, email: 'def@example.com', emailVerified: true, + phoneNumber: '+1800-234-5678', + displayName: 'Def Ghi', + photoURL: 'https://def.googleusercontent.com/ghi/profile_photo.png', clientInitialized: false, _token: null, }) @@ -334,6 +355,9 @@ describe('createAuthUser: firebaseUserAdminSDK', () => { claims: {}, email: 'def@example.com', emailVerified: true, + phoneNumber: '+1800-234-5678', + displayName: 'Def Ghi', + photoURL: 'https://def.googleusercontent.com/ghi/profile_photo.png', clientInitialized: false, _token: 'my-id-token-def-456', }) @@ -363,6 +387,9 @@ describe('createAuthUser: firebaseUserAdminSDK', () => { claims: customClaims, email: 'def@example.com', emailVerified: true, + phoneNumber: '+1800-234-5678', + displayName: 'Def Ghi', + photoURL: 'https://def.googleusercontent.com/ghi/profile_photo.png', clientInitialized: false, _token: 'my-id-token-def-456', }) @@ -383,6 +410,9 @@ describe('createAuthUser: firebaseUserAdminSDK', () => { claims: {}, email: 'def@example.com', emailVerified: true, + phoneNumber: '+1800-234-5678', + displayName: 'Def Ghi', + photoURL: 'https://def.googleusercontent.com/ghi/profile_photo.png', clientInitialized: false, _token: undefined, }) @@ -411,6 +441,9 @@ describe('createAuthUser: serializedAuthUser', () => { id: 'ghi-789', email: 'ghi@example.com', emailVerified: true, + phoneNumber: '+1800-345-6789', + displayName: 'Ghi Jkl', + photoURL: 'https://ghi.googleusercontent.com/jkl/profile_photo.png', clientInitialized: false, getIdToken: expect.any(Function), firebaseUser: null, @@ -436,6 +469,9 @@ describe('createAuthUser: serializedAuthUser', () => { id: 'ghi-789', email: 'ghi@example.com', emailVerified: true, + phoneNumber: '+1800-345-6789', + displayName: 'Ghi Jkl', + photoURL: 'https://ghi.googleusercontent.com/jkl/profile_photo.png', clientInitialized: false, getIdToken: expect.any(Function), firebaseUser: null, diff --git a/src/claims.js b/src/claims.js index 2b73c0b0..dbf03769 100644 --- a/src/claims.js +++ b/src/claims.js @@ -11,6 +11,9 @@ export const STANDARD_CLAIMS = [ 'firebase', 'iat', 'iss', + 'name', + 'phone_number', + 'picture', 'sub', 'uid', 'user_id', // not listed in the decodedIDtoken reference but it appears in tokens diff --git a/src/createAuthUser.js b/src/createAuthUser.js index 3445e61e..967a54dd 100644 --- a/src/createAuthUser.js +++ b/src/createAuthUser.js @@ -99,6 +99,9 @@ const createAuthUser = ({ let userId = null let email = null let emailVerified = false + let phoneNumber = null + let displayName = null + let photoURL = null let getIdTokenFunc = async () => null // When not on the client side, the "signOut" method is a noop. @@ -120,6 +123,9 @@ const createAuthUser = ({ userId = firebaseUserClientSDK.uid email = firebaseUserClientSDK.email emailVerified = firebaseUserClientSDK.emailVerified + phoneNumber = firebaseUserClientSDK.phoneNumber + displayName = firebaseUserClientSDK.displayName + photoURL = firebaseUserClientSDK.photoURL getIdTokenFunc = async () => firebaseUserClientSDK.getIdToken() signOut = async () => firebase.auth().signOut() tokenString = null @@ -135,6 +141,9 @@ const createAuthUser = ({ userId = firebaseUserAdminSDK.uid email = firebaseUserAdminSDK.email emailVerified = firebaseUserAdminSDK.email_verified + phoneNumber = firebaseUserAdminSDK.phone_number + displayName = firebaseUserAdminSDK.name + photoURL = firebaseUserAdminSDK.picture getIdTokenFunc = async () => token tokenString = token } else if (serializedAuthUser) { @@ -143,6 +152,9 @@ const createAuthUser = ({ userId = deserializedUser.id email = deserializedUser.email emailVerified = deserializedUser.emailVerified + phoneNumber = deserializedUser.phoneNumber + displayName = deserializedUser.displayName + photoURL = deserializedUser.photoURL getIdTokenFunc = async () => deserializedUser._token || null tokenString = deserializedUser._token } @@ -150,6 +162,9 @@ const createAuthUser = ({ id: userId, email, emailVerified, + phoneNumber, + displayName, + photoURL, claims: customClaims, // We want the "getIdToken" method to be isomorphic. // When `user` is an AuthUserSerializable object, we take the token @@ -174,6 +189,9 @@ const createAuthUser = ({ claims: customClaims, email, emailVerified, + phoneNumber, + displayName, + photoURL, clientInitialized, ...(includeToken && { _token: tokenString }), }), diff --git a/src/testHelpers/authUserInputs.js b/src/testHelpers/authUserInputs.js index 1e67942d..38dd6eff 100644 --- a/src/testHelpers/authUserInputs.js +++ b/src/testHelpers/authUserInputs.js @@ -2,6 +2,9 @@ export const createMockFirebaseUserClientSDK = () => ({ uid: 'abc-123', email: 'abc@example.com', emailVerified: true, + phoneNumber: '+1800-123-4567', + displayName: 'Abc Cdf', + photoURL: 'https://abc.googleusercontent.com/cdf/profile_photo.png', getIdToken: async () => 'my-id-token-abc-123', claims: {}, // ... other properties @@ -12,6 +15,9 @@ export const createMockFirebaseUserAdminSDK = () => ({ uid: 'def-456', email: 'def@example.com', email_verified: true, + phone_number: '+1800-234-5678', + name: 'Def Ghi', + picture: 'https://def.googleusercontent.com/ghi/profile_photo.png', iss: 'https://securetoken.google.com/my-cool-app', aud: 'my-cool-app', auth_time: 1540000000, @@ -40,6 +46,9 @@ export const createMockSerializedAuthUser = ({ claims = {} } = {}) => claims, email: 'ghi@example.com', emailVerified: true, + phoneNumber: '+1800-345-6789', + displayName: 'Ghi Jkl', + photoURL: 'https://ghi.googleusercontent.com/jkl/profile_photo.png', clientInitialized: false, _token: 'my-id-token-ghi-789', })