diff --git a/src/app/api/auth/[...nextauth]/route.ts b/src/app/api/auth/[...nextauth]/route.ts index 090dd83a..57219b4b 100644 --- a/src/app/api/auth/[...nextauth]/route.ts +++ b/src/app/api/auth/[...nextauth]/route.ts @@ -25,7 +25,20 @@ const handler = NextAuth({ } }, } - ] + ], + callbacks: { + async jwt({ token, account, profile }) { + // Persist the OAuth access_token and or the user id to the token right after signin + if (account && profile) { + token.id = profile.id, + token.name = profile.name_zh, + token.name_en = profile.name_en, + token.inschool = profile.inschool, + token.email = profile.email + } + return token + } + } }) export { handler as GET, handler as POST } diff --git a/src/types/next-auth.d.ts b/src/types/next-auth.d.ts new file mode 100644 index 00000000..0ae4944d --- /dev/null +++ b/src/types/next-auth.d.ts @@ -0,0 +1,22 @@ +import NextAuth, { DefaultSession } from "next-auth" + +declare module "next-auth" { + interface Profile { + id: string, + inschool: boolean, + name_zh: string, + name_en: string, + email: string + } + interface Session { + user: { + id: string, + inschool: boolean, + name_zh: string, + name_en: string, + email: string + } & DefaultSession["user"] + } +} + +