-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.ts
More file actions
executable file
·68 lines (62 loc) · 1.73 KB
/
Copy pathauth.ts
File metadata and controls
executable file
·68 lines (62 loc) · 1.73 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
import NextAuth from "next-auth"
import "next-auth/jwt"
import { providers } from "@/auth.providers"
import { canSignIn } from "@/lib/auth"
import { prisma } from "@/lib/prisma"
import { PrismaAdapter } from "@auth/prisma-adapter"
export { providerMap } from "@/auth.providers"
export const { handlers, auth, signIn, signOut } = NextAuth({
debug: process.env.NODE_ENV === "development",
theme: { logo: undefined, colorScheme: "auto" },
adapter: PrismaAdapter(prisma),
providers,
basePath: "/auth",
session: { strategy: "jwt" },
pages: {
signIn: "/signin",
},
callbacks: {
async signIn({ user, account, profile }) {
// Check if user can sign in (not blocked)
if (user.email) {
const canUserSignIn = await canSignIn(user.email)
if (!canUserSignIn) {
return false
}
}
return true
},
jwt({ token, trigger, session, account, user }) {
if (trigger === "update") token.name = session.user.name
if (account && user) {
token.id = user.id
}
if (account?.provider === "github" || account?.provider === "linkedin") {
return { ...token, accessToken: account.access_token, refreshToken: account.refresh_token }
}
return token
},
async session({ session, token }) {
if (token?.accessToken) session.accessToken = token.accessToken
if (token?.id) session.user.id = token.id as string
return session
},
},
})
declare module "next-auth" {
interface Session {
accessToken?: string
user: {
id: string
name?: string | null
email?: string | null
image?: string | null
}
}
}
declare module "next-auth/jwt" {
interface JWT {
accessToken?: string
id?: string
}
}