-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.ts
More file actions
84 lines (80 loc) · 2.12 KB
/
auth.ts
File metadata and controls
84 lines (80 loc) · 2.12 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { DrizzleAdapter } from "@auth/drizzle-adapter"
import NextAuth from "next-auth"
import type { Provider } from "next-auth/providers"
import Google from "next-auth/providers/google"
import Resend from "next-auth/providers/resend"
import { db } from "./drizzle/db"
import {
accounts,
authenticators,
sessions,
users,
verificationTokens,
} from "./drizzle/schema"
import { googleOauthEnabled, resendEnabled } from "./lib/constants"
import { customSendVerificationRequest } from "./lib/email"
/**
* Providers
*
* This is the list of providers that are supported.
* Resend is used for sending emails (magic links).
* Google is used for authentication.
* @link https://authjs.dev/getting-started/providers/resend
* @link https://authjs.dev/getting-started/providers/google
* @returns {Provider[]} - The list of providers.
*/
export const providers: Provider[] = [
...(resendEnabled
? [
Resend({
apiKey: process.env.RESEND_API_KEY,
from: process.env.AUTH_EMAIL_FROM,
sendVerificationRequest: customSendVerificationRequest,
}),
]
: []),
...(googleOauthEnabled
? [
Google({
allowDangerousEmailAccountLinking: true, // we trust that Google has verified the email
}),
]
: []),
]
/**
* Adapter
*
* This is the adapter that is used to connect to the database.
*
* @link https://authjs.dev/reference/drizzle-adapter
*/
const adapter = DrizzleAdapter(db, {
usersTable: users,
sessionsTable: sessions,
accountsTable: accounts,
authenticatorsTable: authenticators,
verificationTokensTable: verificationTokens,
})
/**
* Auth Configuration
*
* @link https://authjs.dev/getting-started/migrating-to-v5
**/
export const { auth, handlers, signIn, signOut } = NextAuth({
providers,
adapter,
pages: {
signIn: "/sign-in",
},
callbacks: {
session({ session, user }) {
session.user.role = user.role
return session
},
async signIn({}) {
// You can add custom sign-in logic here, for example if you want to do a custom check for the user
// before signing them in.
return true
},
},
})