fix: on change email request for unverified emails should use the newEmail on verification token payload (#1801)

This commit is contained in:
Bereket Engida
2025-03-13 13:02:23 +03:00
committed by GitHub
parent 79b56f5db6
commit 6efc752682
2 changed files with 20 additions and 1 deletions
@@ -89,6 +89,25 @@ describe("updateUser", async () => {
},
});
expect(session.user.email).toBe(newEmail);
expect(session.user.emailVerified).toBe(false);
});
it("should verify email", async () => {
await client.verifyEmail({
query: {
token: emailVerificationToken,
},
fetchOptions: {
headers,
},
});
const session = await client.getSession({
fetchOptions: {
headers,
throw: true,
},
});
expect(session.user.emailVerified).toBe(true);
});
it("should send email verification before update", async () => {
@@ -612,8 +612,8 @@ export const changeEmail = createAuthEndpoint(
if (ctx.context.options.emailVerification?.sendVerificationEmail) {
const token = await createEmailVerificationToken(
ctx.context.secret,
ctx.context.session.user.email,
newEmail,
undefined,
ctx.context.options.emailVerification?.expiresIn,
);
const url = `${