Skip to content

Commit 6c73cd6

Browse files
fix(auth): Fix incorrect import of partial user metadata. (#445)
* Fix incorrect import of partial user metadata. * Remove validating metadata for null.
1 parent 18d371c commit 6c73cd6

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

auth/import_users.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,15 @@ func (u *UserToImport) PhoneNumber(phoneNumber string) *UserToImport {
143143

144144
// Metadata setter.
145145
func (u *UserToImport) Metadata(metadata *UserMetadata) *UserToImport {
146-
u.set("createdAt", metadata.CreationTimestamp)
147-
return u.set("lastLoginAt", metadata.LastLogInTimestamp)
146+
if metadata.CreationTimestamp != 0 {
147+
u.set("createdAt", metadata.CreationTimestamp)
148+
}
149+
150+
if metadata.LastLogInTimestamp != 0 {
151+
u.set("lastLoginAt", metadata.LastLogInTimestamp)
152+
}
153+
154+
return u
148155
}
149156

150157
// CustomClaims setter.

auth/user_mgt_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,6 +1184,24 @@ func TestUserToImport(t *testing.T) {
11841184
"lastLoginAt": int64(150),
11851185
},
11861186
},
1187+
{
1188+
user: (&UserToImport{}).UID("test").Metadata(&UserMetadata{
1189+
CreationTimestamp: int64(100),
1190+
}),
1191+
want: map[string]interface{}{
1192+
"localId": "test",
1193+
"createdAt": int64(100),
1194+
},
1195+
},
1196+
{
1197+
user: (&UserToImport{}).UID("test").Metadata(&UserMetadata{
1198+
LastLogInTimestamp: int64(150),
1199+
}),
1200+
want: map[string]interface{}{
1201+
"localId": "test",
1202+
"lastLoginAt": int64(150),
1203+
},
1204+
},
11871205
{
11881206
user: (&UserToImport{}).UID("test").PasswordHash([]byte("password")),
11891207
want: map[string]interface{}{

0 commit comments

Comments
 (0)