-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.ts
More file actions
65 lines (61 loc) · 2.04 KB
/
auth.ts
File metadata and controls
65 lines (61 loc) · 2.04 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
import NextAuth from "next-auth";
import GitHubProvider from "next-auth/providers/github";
import { PrismaAdapter } from "@auth/prisma-adapter";
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
export const { handlers, signIn, signOut, auth } = NextAuth({
adapter: PrismaAdapter(prisma),
providers: [
GitHubProvider({
clientId: process.env.AUTH_GITHUB_ID,
clientSecret: process.env.AUTH_GITHUB_SECRET,
}),
],
session: { strategy: "jwt" },
callbacks: {
async signIn({ user }) {
// Ensure email is a non-null string
if (!user.email) {
console.error("User email is undefined");
return false;
}
return true;
},
},
events: {
async createUser({ user }) {
// Ensure email is a non-null string
if (!user.email) {
console.error("User email is undefined");
return;
}
// Add records to the database for the first-time user
try {
const flow = await prisma.flow.create({
data: {
user: {
connect: {
email: user.email,
},
},
name: "default-flow",
nodes: {
create: [
{
type: "characters",
data: { characters: ["Player", "Narrator"] },
position: { x: 250, y: 5 },
},
],
},
},
include: {
nodes: true,
},
});
} catch (error) {
console.error("Error creating flow: ", error);
}
},
},
});