1
0
Fork 0
mirror of synced 2024-09-20 11:27:56 +12:00

Allow updating email

This commit is contained in:
Adria Navarro 2024-07-03 12:18:06 +02:00
parent 3ed9c9a4a5
commit 19e4e8fdb4
3 changed files with 20 additions and 2 deletions

View file

@ -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) {

View file

@ -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,
})
)
})
})
})
})
})

View file

@ -3,4 +3,5 @@ export interface SaveUserOpts {
requirePassword?: boolean
currentUserId?: string
skipPasswordValidation?: boolean
allowChangingEmail?: boolean
}