Skip to content

Commit 18dbc4b

Browse files
committed
fix undefined value in lastSignInTime when user just created
1 parent fe3d410 commit 18dbc4b

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

spec/providers/auth.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,35 @@ describe('Auth Functions', () => {
175175
lastSignInTime: null,
176176
},
177177
});
178+
179+
});
180+
181+
it('will make lastSignInTime null if missing from metadata object (upon creation and no sign in yet)', () => {
182+
const record = auth.userRecordConstructor({
183+
metadata: {
184+
creationTime: '2017-02-02T23:06:26.124Z',
185+
}
186+
});
187+
expect(record.toJSON()).to.deep.equal({
188+
email: null,
189+
emailVerified: false,
190+
displayName: null,
191+
photoURL: null,
192+
phoneNumber: null,
193+
disabled: false,
194+
providerData: [],
195+
customClaims: {},
196+
passwordSalt: null,
197+
passwordHash: null,
198+
tokensValidAfterTime: null,
199+
metadata: {
200+
creationTime: '2017-02-02T23:06:26.124Z',
201+
lastSignInTime: null,
202+
},
203+
});
178204
});
179205

206+
180207
it('will not interfere with fields that are in raw wire data', () => {
181208
const raw: any = {
182209
uid: '123',

src/providers/auth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export function userRecordConstructor(
143143
new UserRecordMetadata(
144144
// Transform payload to firebase-admin v5.0.0 format because wire format is different (BUG 63167395)
145145
meta.createdAt || meta.creationTime,
146-
meta.lastSignedInAt || meta.lastSignInTime
146+
meta.lastSignedInAt || meta.lastSignInTime || null
147147
)
148148
);
149149
} else {

0 commit comments

Comments
 (0)