Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Fixes bug where auth.UserRecord.metadata was undefined.
2 changes: 2 additions & 0 deletions integration_test/functions/src/auth-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down
15 changes: 15 additions & 0 deletions spec/providers/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
5 changes: 4 additions & 1 deletion src/providers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down