-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.ts
36 lines (32 loc) · 846 Bytes
/
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
import NextAuth from 'next-auth'
import Github from 'next-auth/providers/github'
import { PrismaAdapter } from '@auth/prisma-adapter'
import { db } from '@/db'
const GITHUB_CLIENT_ID = process.env.GITHUB_CLIENT_ID
const GITHUB_CLIENT_SECRET = process.env.GITHUB_CLIENT_SECRET
if (!GITHUB_CLIENT_ID || !GITHUB_CLIENT_SECRET) {
throw new Error('Missing Github OAuth Credentials')
}
export const {
handlers: { GET, POST },
auth,
signOut,
signIn,
} = NextAuth({
adapter: PrismaAdapter(db),
providers: [
Github({
clientId: GITHUB_CLIENT_ID,
clientSecret: GITHUB_CLIENT_SECRET,
}),
],
callbacks: {
// Usuallly not needed, here we are fixing a bug in next-auth
async session({ session, user }) {
if (session && user) {
session.user.id = user.id
}
return session
},
},
})