-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathauth.ts
More file actions
53 lines (50 loc) · 1.52 KB
/
auth.ts
File metadata and controls
53 lines (50 loc) · 1.52 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
import NextAuth, { NextAuthConfig } from "next-auth"
import SlackProvider from "next-auth/providers/slack"
import { PrismaAdapter } from "@auth/prisma-adapter"
import prisma, { setUserDefaultInventory } from "@/lib/prisma"
import { getPersonData } from "./lib/person"
export const config: any = {
theme: {
logo: "",
},
debug: true,
adapter: PrismaAdapter(prisma),
providers: [
SlackProvider({
clientId: process.env.CLIENT_ID!,
clientSecret: process.env.CLIENT_SECRET!,
checks: ['pkce', 'nonce'],
}),
],
events: {
async signIn({user, account, profile, isNewUser}: {user: any, account: any, profile: any, isNewUser: any}) {
const people = await getPersonData(user.email!) as any
const r = await prisma.user.update({
where: {
id: user.id!
},
data: {
nickname: people["display_name"] ? people["display_name"] : people["real_name"] ,
}
})
if (isNewUser){
setUserDefaultInventory(user.id!)
// manually assign slack id because no jwt
await prisma.user.update({
where: {
id: user.id!
},
data: {
providerAccountId: profile?.sub!,
}
})
}
}
},
callbacks: {
async session({session, token, user, trigger}: {session: any, token: any, user: any, trigger: any}) {
return { ...session, providerAccountId: user.providerAccountId }
},
},
}
export const { handlers, auth, signIn, signOut } = NextAuth(config)