-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.ts
65 lines (59 loc) · 1.41 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
58
59
60
61
62
63
64
65
import NextAuth, { type DefaultSession } from "next-auth"
import Google from "next-auth/providers/google"
import Resend from "next-auth/providers/resend"
import type { Provider } from "next-auth/providers"
import PostgresAdapter from "@auth/pg-adapter"
import { pgpool } from "./db"
import { authEvents } from "./authEvents"
declare module "next-auth" {
interface User {
id?: string
name?: string | null
email?: string | null
image?: string | null
role?: string | "student" | null
}
interface Session {
user: {
role: string
} & DefaultSession["user"]
}
}
const providers: Provider[] = [
Google,
Resend(
{
from: "auth@school.vld-group.com",
}
)
]
export const providerMap = providers.map((provider) => {
if (typeof provider === "function") {
const providerData = provider()
return { id: providerData.id, name: providerData.name }
} else {
return { id: provider.id, name: provider.name }
}
})
export const { handlers, auth, signIn, signOut } = NextAuth({
adapter: PostgresAdapter(pgpool),
providers,
pages: {
signIn: "/auth",
signOut: "/auth/signout",
error: "/auth/error",
verifyRequest: "/auth/verify-request",
},
callbacks: {
session({ session, token, user }) {
return {
...session,
user: {
...session.user,
role: user.role,
},
}
},
},
events: authEvents,
})