Skip to content

Commit 298f66f

Browse files
authored
Fix auth UserRecord.metadata regression (#481)
* fix auth regression * adding unit and integration tests to test the wire format conversion for auth * add changelog for release
1 parent 2563b99 commit 298f66f

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* Fixes bug where auth.UserRecord.metadata was undefined.

integration_test/functions/src/auth-tests.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ export const createUserTests: any = functions.auth.user().onCreate((u, c) => {
3232
expectEq((context as any).action, undefined)
3333
)
3434

35+
.it('should have properly defined meta', (user, context) => user.metadata)
36+
3537
.run(testId, u, c);
3638
});
3739

spec/providers/auth.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,21 @@ describe('Auth Functions', () => {
178178
const record = auth.userRecordConstructor(raw);
179179
expect(record.toJSON()).to.deep.equal(raw);
180180
});
181+
182+
it('will convert raw wire fields createdAt and lastSignedInAt to creationTime and lastSignInTime', () => {
183+
const raw: any = {
184+
uid: '123',
185+
metadata: {
186+
createdAt: '2017-02-02T23:06:26.124Z',
187+
lastSignedInAt: '2017-02-02T23:01:19.797Z',
188+
},
189+
};
190+
const record = auth.userRecordConstructor(raw);
191+
expect(record.metadata).to.deep.equal({
192+
creationTime: '2017-02-02T23:06:26.124Z',
193+
lastSignInTime: '2017-02-02T23:01:19.797Z',
194+
});
195+
});
181196
});
182197

183198
describe('handler namespace', () => {

src/providers/auth.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@ export function userRecordConstructor(
140140
_.set(
141141
record,
142142
'metadata',
143-
new UserRecordMetadata(meta.creationTime, meta.lastSignInTime)
143+
new UserRecordMetadata(
144+
meta.createdAt || meta.creationTime,
145+
meta.lastSignedInAt || meta.lastSignInTime
146+
)
144147
);
145148
} else {
146149
_.set(record, 'metadata', new UserRecordMetadata(null, null));

0 commit comments

Comments
 (0)