From 871cdb83e607f1b7aa10b8ee1ef1e229e48ed57d Mon Sep 17 00:00:00 2001 From: Adrien Zaganelli Date: Wed, 2 Oct 2024 15:20:32 +0200 Subject: [PATCH] feat(session): add email_verified in session's user --- playground/server/routes/auth/github.get.ts | 11 ++++++++++- src/runtime/types.ts | 5 ++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/playground/server/routes/auth/github.get.ts b/playground/server/routes/auth/github.get.ts index efe1990..432f957 100644 --- a/playground/server/routes/auth/github.get.ts +++ b/playground/server/routes/auth/github.get.ts @@ -1,9 +1,12 @@ +import { drizzle as drizzleIntegration } from "db0/integrations/drizzle/index"; + export default defineOAuthGitHubEventHandler({ config: { emailRequired: true, }, async onSuccess(event, { user }) { const auth = useSlipAuth(); + const db = drizzleIntegration(useDatabase()); const [userId, sessionFromDb] = await auth.OAuthLoginUser({ email: user.email, @@ -13,14 +16,20 @@ export default defineOAuthGitHubEventHandler({ ip: getRequestIP(event), }); + const userDb = await db + .select() + .from(auth.schemas.users) + .get(); + await setUserSession(event, { expires_at: sessionFromDb.expires_at, id: sessionFromDb.id, user: { id: userId, + email_verified: userDb?.email_verified || false, }, }); - return sendRedirect(event, "/"); + return sendRedirect(event, "/profile"); }, // Optional, will return a json error and 401 status code by default onError(event, error) { diff --git a/src/runtime/types.ts b/src/runtime/types.ts index 410199a..a7e8d7d 100644 --- a/src/runtime/types.ts +++ b/src/runtime/types.ts @@ -31,12 +31,11 @@ declare module "nuxt/schema" { export type SlipAuthPublicSession = Pick; -// eslint-disable-next-line @typescript-eslint/ban-ts-comment -// @ts-ignore #auth-utils is an alias from nuxt-auth-utils +// @ts-expect-error #auth-utils is an alias from nuxt-auth-utils declare module "#auth-utils" { // eslint-disable-next-line @typescript-eslint/no-empty-object-type interface UserSession extends SlipAuthPublicSession {} // eslint-disable-next-line @typescript-eslint/no-empty-object-type - interface User extends Pick {} + interface User extends Pick {} }