-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.ts
More file actions
37 lines (34 loc) · 1012 Bytes
/
Copy pathauth.ts
File metadata and controls
37 lines (34 loc) · 1012 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { PrismaAdapter } from "@auth/prisma-adapter";
import NextAuth, { Session } from "next-auth";
import GitHub from "next-auth/providers/github";
import Google from "next-auth/providers/google";
import { db } from "./lib/prisma";
import { JWT } from "next-auth/jwt";
export const { handlers, signIn, signOut, auth } = NextAuth({
adapter: PrismaAdapter(db),
providers: [Google, GitHub],
callbacks: {
jwt({ token, user }) {
if (user) {
token.id = user.id;
}
return token;
},
async session({ session, token }: { session: Session; token: JWT }) {
const user = await db.user.findUnique({
where: { id: token.sub },
});
if (session.user && user) {
session.user.id = user.id as string;
session.user.name = user.name;
session.user.email = user.email;
session.user.image = user.image;
session.user.bio = user.bio ?? "";
}
return session;
},
},
session: {
strategy: "jwt",
},
});