From b130196951fd934e8d2adcb03e72163a2fc3e896 Mon Sep 17 00:00:00 2001 From: ImJustChew Date: Sat, 4 Nov 2023 23:36:29 +0800 Subject: [PATCH] =?UTF-8?q?try=20again=20=F0=9F=91=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/api/auth/[...nextauth]/route.ts | 20 ++++++++++++++++++-- src/types/next-auth.d.ts | 8 ++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/app/api/auth/[...nextauth]/route.ts b/src/app/api/auth/[...nextauth]/route.ts index d81d578a..2034d377 100644 --- a/src/app/api/auth/[...nextauth]/route.ts +++ b/src/app/api/auth/[...nextauth]/route.ts @@ -66,13 +66,29 @@ const handler = NextAuth({ if (account) { token.id = user.id, - token.name = user.name_zh, + token.name_zh = user.name_zh, token.name_en = user.name_en, token.inschool = user.inschool, token.email = user.email } return token - } + }, + async session({ session, token }) { + session.user = { + ...session.user, + //@ts-ignore + id: token.id, + //@ts-ignore + name_zh: token.name_zh, + //@ts-ignore + name_en: token.name_en, + //@ts-ignore + inschool: token.inschool, + //@ts-ignore + email: token.email + } + return session; + }, } }) diff --git a/src/types/next-auth.d.ts b/src/types/next-auth.d.ts index f9cea4d1..a7722991 100644 --- a/src/types/next-auth.d.ts +++ b/src/types/next-auth.d.ts @@ -1,4 +1,5 @@ import NextAuth, { DefaultSession } from "next-auth" +import { DefaultJWT } from "next-auth/jwt" declare module "next-auth" { interface User { @@ -8,6 +9,13 @@ declare module "next-auth" { name_en: string, email: string } + interface JWT extends DefaultJWT { + id: string, + inschool: boolean, + name_zh: string, + name_en: string, + email: string + } interface Session { user: { id: string,