-
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) · 869 Bytes
/
Copy pathauth.ts
File metadata and controls
37 lines (34 loc) · 869 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 NextAuth from "next-auth";
import Google from "next-auth/providers/google";
import { PrismaAdapter } from "@auth/prisma-adapter";
import { prisma } from "./lib/prisma";
let nextAuthResult;
try {
nextAuthResult = NextAuth({
adapter: PrismaAdapter(prisma),
providers: [
Google({
clientId: process.env.AUTH_GOOGLE_ID!,
clientSecret: process.env.AUTH_GOOGLE_SECRET!,
}),
],
callbacks: {
session({ session, token }) {
if (session.user && token.sub) {
session.user.id = token.sub;
}
return session;
},
},
pages: {
signIn: "/auth/signin",
},
session: {
strategy: "jwt",
},
});
} catch (error) {
console.error("ERROR in NextAuth initialization:", error);
throw error;
}
export const { handlers, auth, signIn, signOut } = nextAuthResult;