-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.ts
57 lines (55 loc) · 1.46 KB
/
auth.ts
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import NextAuth from "next-auth";
import EmailProvider from "next-auth/providers/nodemailer";
import GoogleProvider from "next-auth/providers/google";
import { PrismaAdapter } from "@auth/prisma-adapter";
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
export const { auth, handlers, signIn, signOut } = NextAuth({
adapter: PrismaAdapter(prisma),
providers: [
EmailProvider({
server: {
host: process.env.EMAIL_SERVER_HOST,
port: process.env.EMAIL_SERVER_PORT,
auth: {
user: process.env.EMAIL_SERVER_USER,
pass: process.env.EMAIL_SERVER_PASSWORD,
},
},
from: process.env.EMAIL_FROM,
}),
GoogleProvider({
clientId: process.env.GOOGLE_AUTH_CLIENT_ID ?? "",
clientSecret: process.env.GOOGLE_AUTH_CLIENT_SECRET ?? "",
profile(profile) {
return {
id: profile?.sub ?? "",
email: profile?.email ?? "",
emailVerified: profile?.email_verified ?? "",
username: profile?.name ?? "",
image: profile?.picture ?? "",
};
},
}),
],
session: {
strategy: "database",
},
secret: process.env.NEXTAUTH_SECRET,
callbacks: {
async session({ session, user }) {
if (session?.user && user?.id) {
return {
...session,
user: {
...user,
},
};
}
return session;
},
},
theme: {
colorScheme: "dark",
},
});