mirror of
https://github.com/LukeHagar/better-auth.git
synced 2025-12-09 04:19:26 +00:00
fix(email-otp): email-verification doesn't trigger session signal (#5219)
This commit is contained in:
@@ -5,5 +5,11 @@ export const emailOTPClient = () => {
|
|||||||
return {
|
return {
|
||||||
id: "email-otp",
|
id: "email-otp",
|
||||||
$InferServerPlugin: {} as ReturnType<typeof emailOTP>,
|
$InferServerPlugin: {} as ReturnType<typeof emailOTP>,
|
||||||
|
atomListeners: [
|
||||||
|
{
|
||||||
|
matcher: (path) => path === "/email-otp/verify-email",
|
||||||
|
signal: "$sessionSignal",
|
||||||
|
},
|
||||||
|
],
|
||||||
} satisfies BetterAuthClientPlugin;
|
} satisfies BetterAuthClientPlugin;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import * as z from "zod";
|
import * as z from "zod";
|
||||||
import { APIError } from "../../api";
|
import { APIError, getSessionFromCtx } from "../../api";
|
||||||
import {
|
import {
|
||||||
createAuthEndpoint,
|
createAuthEndpoint,
|
||||||
createAuthMiddleware,
|
createAuthMiddleware,
|
||||||
@@ -11,7 +11,7 @@ import {
|
|||||||
symmetricEncrypt,
|
symmetricEncrypt,
|
||||||
} from "../../crypto";
|
} from "../../crypto";
|
||||||
import { getDate } from "../../utils/date";
|
import { getDate } from "../../utils/date";
|
||||||
import { setSessionCookie } from "../../cookies";
|
import { setCookieCache, setSessionCookie } from "../../cookies";
|
||||||
import { getEndpointResponse } from "../../utils/plugin-helper";
|
import { getEndpointResponse } from "../../utils/plugin-helper";
|
||||||
import { defaultKeyHasher, splitAtLastColon } from "./utils";
|
import { defaultKeyHasher, splitAtLastColon } from "./utils";
|
||||||
import type { GenericEndpointContext } from "@better-auth/core";
|
import type { GenericEndpointContext } from "@better-auth/core";
|
||||||
@@ -727,7 +727,24 @@ export const emailOTP = (options: EmailOTPOptions) => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
const currentSession = await getSessionFromCtx(ctx);
|
||||||
|
if (currentSession && updatedUser.emailVerified) {
|
||||||
|
const dontRememberMeCookie = await ctx.getSignedCookie(
|
||||||
|
ctx.context.authCookies.dontRememberToken.name,
|
||||||
|
ctx.context.secret,
|
||||||
|
);
|
||||||
|
await setCookieCache(
|
||||||
|
ctx,
|
||||||
|
{
|
||||||
|
session: currentSession.session,
|
||||||
|
user: {
|
||||||
|
...currentSession.user,
|
||||||
|
emailVerified: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
!!dontRememberMeCookie,
|
||||||
|
);
|
||||||
|
}
|
||||||
return ctx.json({
|
return ctx.json({
|
||||||
status: true,
|
status: true,
|
||||||
token: null,
|
token: null,
|
||||||
|
|||||||
Reference in New Issue
Block a user