-
Notifications
You must be signed in to change notification settings - Fork 1
/
auth.config.mjs
45 lines (43 loc) · 1.36 KB
/
auth.config.mjs
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
import Google from '@auth/core/providers/google';
import GitHub from '@auth/core/providers/github';
import { defineConfig } from 'auth-astro';
import { db } from "@prisma";
export default defineConfig({
providers: [
Google({
clientId: import.meta.env.GOOGLE_CLIENT_ID,
clientSecret: import.meta.env.GOOGLE_CLIENT_SECRET,
}),
GitHub({
clientId: import.meta.env.GITHUB_CLIENT_ID,
clientSecret: import.meta.env.GITHUB_CLIENT_SECRET,
}),
],
callbacks: {
async session({ session }) {
try {
const user = await db.user.findUnique({
where: {
email: session.user.email,
},
})
if (!user) {
await db.user.create({
data: {
email: session.user.email,
name: session.user.name,
image: session.user.image,
progress: {
create: {}
}
},
})
}
} catch (error) {
console.log("Auth error: ", error)
} finally {
return session
}
}
},
});