mirror of
https://github.com/better-auth/better-auth.git
synced 2026-07-30 17:12:35 -05:00
fix: on change email request for unverified emails should use the newEmail on verification token payload (#1801)
This commit is contained in:
@@ -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 = `${
|
||||
|
||||
Reference in New Issue
Block a user