Skip to content

Commit

Permalink
Merge pull request #156 from ghatchue/main
Browse files Browse the repository at this point in the history
Return phone number, display name and photo URL when creating AuthUser
  • Loading branch information
kmjennison authored May 9, 2021
2 parents 333d538 + 1dfe960 commit a32a269
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
3 changes: 3 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string | boolean>
getIdToken: () => Promise<string | null>
clientInitialized: boolean
Expand Down
36 changes: 36 additions & 0 deletions src/__tests__/createAuthUser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -121,6 +124,9 @@ describe('createAuthUser: firebaseUserClientSDK', () => {
id: 'abc-123',
email: '[email protected]',
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,
Expand Down Expand Up @@ -149,6 +155,9 @@ describe('createAuthUser: firebaseUserClientSDK', () => {
id: 'abc-123',
email: '[email protected]',
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,
Expand Down Expand Up @@ -197,6 +206,9 @@ describe('createAuthUser: firebaseUserClientSDK', () => {
claims: {},
email: '[email protected]',
emailVerified: true,
phoneNumber: '+1800-123-4567',
displayName: 'Abc Cdf',
photoURL: 'https://abc.googleusercontent.com/cdf/profile_photo.png',
clientInitialized: false,
_token: null,
})
Expand Down Expand Up @@ -234,6 +246,9 @@ describe('createAuthUser: firebaseUserAdminSDK', () => {
id: 'def-456',
email: '[email protected]',
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,
Expand All @@ -255,6 +270,9 @@ describe('createAuthUser: firebaseUserAdminSDK', () => {
id: 'def-456',
email: '[email protected]',
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,
Expand Down Expand Up @@ -314,6 +332,9 @@ describe('createAuthUser: firebaseUserAdminSDK', () => {
claims: {},
email: '[email protected]',
emailVerified: true,
phoneNumber: '+1800-234-5678',
displayName: 'Def Ghi',
photoURL: 'https://def.googleusercontent.com/ghi/profile_photo.png',
clientInitialized: false,
_token: null,
})
Expand All @@ -334,6 +355,9 @@ describe('createAuthUser: firebaseUserAdminSDK', () => {
claims: {},
email: '[email protected]',
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',
})
Expand Down Expand Up @@ -363,6 +387,9 @@ describe('createAuthUser: firebaseUserAdminSDK', () => {
claims: customClaims,
email: '[email protected]',
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',
})
Expand All @@ -383,6 +410,9 @@ describe('createAuthUser: firebaseUserAdminSDK', () => {
claims: {},
email: '[email protected]',
emailVerified: true,
phoneNumber: '+1800-234-5678',
displayName: 'Def Ghi',
photoURL: 'https://def.googleusercontent.com/ghi/profile_photo.png',
clientInitialized: false,
_token: undefined,
})
Expand Down Expand Up @@ -411,6 +441,9 @@ describe('createAuthUser: serializedAuthUser', () => {
id: 'ghi-789',
email: '[email protected]',
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,
Expand All @@ -436,6 +469,9 @@ describe('createAuthUser: serializedAuthUser', () => {
id: 'ghi-789',
email: '[email protected]',
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,
Expand Down
3 changes: 3 additions & 0 deletions src/claims.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions src/createAuthUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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) {
Expand All @@ -143,13 +152,19 @@ 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
}
return {
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
Expand All @@ -174,6 +189,9 @@ const createAuthUser = ({
claims: customClaims,
email,
emailVerified,
phoneNumber,
displayName,
photoURL,
clientInitialized,
...(includeToken && { _token: tokenString }),
}),
Expand Down
9 changes: 9 additions & 0 deletions src/testHelpers/authUserInputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ export const createMockFirebaseUserClientSDK = () => ({
uid: 'abc-123',
email: '[email protected]',
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
Expand All @@ -12,6 +15,9 @@ export const createMockFirebaseUserAdminSDK = () => ({
uid: 'def-456',
email: '[email protected]',
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,
Expand Down Expand Up @@ -40,6 +46,9 @@ export const createMockSerializedAuthUser = ({ claims = {} } = {}) =>
claims,
email: '[email protected]',
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',
})

0 comments on commit a32a269

Please sign in to comment.