diff --git a/changelog.txt b/changelog.txt index e69de29bb..03f1fb9d3 100644 --- a/changelog.txt +++ b/changelog.txt @@ -0,0 +1 @@ +* Fixes bug where auth.UserRecord.metadata was undefined. \ No newline at end of file diff --git a/integration_test/functions/src/auth-tests.ts b/integration_test/functions/src/auth-tests.ts index 7b7f8686c..aaef21e6a 100644 --- a/integration_test/functions/src/auth-tests.ts +++ b/integration_test/functions/src/auth-tests.ts @@ -32,6 +32,8 @@ export const createUserTests: any = functions.auth.user().onCreate((u, c) => { expectEq((context as any).action, undefined) ) + .it('should have properly defined meta', (user, context) => user.metadata) + .run(testId, u, c); }); diff --git a/spec/providers/auth.spec.ts b/spec/providers/auth.spec.ts index 676e973ce..bee3435e0 100644 --- a/spec/providers/auth.spec.ts +++ b/spec/providers/auth.spec.ts @@ -178,6 +178,21 @@ describe('Auth Functions', () => { const record = auth.userRecordConstructor(raw); expect(record.toJSON()).to.deep.equal(raw); }); + + it('will convert raw wire fields createdAt and lastSignedInAt to creationTime and lastSignInTime', () => { + const raw: any = { + uid: '123', + metadata: { + createdAt: '2017-02-02T23:06:26.124Z', + lastSignedInAt: '2017-02-02T23:01:19.797Z', + }, + }; + const record = auth.userRecordConstructor(raw); + expect(record.metadata).to.deep.equal({ + creationTime: '2017-02-02T23:06:26.124Z', + lastSignInTime: '2017-02-02T23:01:19.797Z', + }); + }); }); describe('handler namespace', () => { diff --git a/src/providers/auth.ts b/src/providers/auth.ts index 708aca5ad..95747ede5 100644 --- a/src/providers/auth.ts +++ b/src/providers/auth.ts @@ -140,7 +140,10 @@ export function userRecordConstructor( _.set( record, 'metadata', - new UserRecordMetadata(meta.creationTime, meta.lastSignInTime) + new UserRecordMetadata( + meta.createdAt || meta.creationTime, + meta.lastSignedInAt || meta.lastSignInTime + ) ); } else { _.set(record, 'metadata', new UserRecordMetadata(null, null));