Allow updating email
This commit is contained in:
parent
3ed9c9a4a5
commit
19e4e8fdb4
|
@ -232,8 +232,8 @@ export class UserDB {
|
|||
// try to get existing user from db
|
||||
try {
|
||||
dbUser = (await db.get(_id)) as User
|
||||
if (email && dbUser.email !== email) {
|
||||
throw "Email address cannot be changed"
|
||||
if (email && dbUser.email !== email && !opts.allowChangingEmail) {
|
||||
throw new Error("Email address cannot be changed")
|
||||
}
|
||||
email = dbUser.email
|
||||
} catch (e: any) {
|
||||
|
|
|
@ -131,6 +131,23 @@ describe("UserDB", () => {
|
|||
).rejects.toThrow("Email address cannot be changed")
|
||||
})
|
||||
})
|
||||
|
||||
it("email can be updated if specified", async () => {
|
||||
await config.doInTenant(async () => {
|
||||
user.email = generator.email({})
|
||||
|
||||
await db.save(user, { allowChangingEmail: true })
|
||||
|
||||
const persistedUser = await db.getUserByEmail(user.email)
|
||||
expect(persistedUser).toEqual(
|
||||
expect.objectContaining({
|
||||
_id: user._id,
|
||||
email: user.email,
|
||||
lastName: user.lastName,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -3,4 +3,5 @@ export interface SaveUserOpts {
|
|||
requirePassword?: boolean
|
||||
currentUserId?: string
|
||||
skipPasswordValidation?: boolean
|
||||
allowChangingEmail?: boolean
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue