Skip to content

Commit 58f2b7e

Browse files
committed
feat: save auth data in db, add Discord provider
1 parent f40cc45 commit 58f2b7e

File tree

6 files changed

+99
-23
lines changed

6 files changed

+99
-23
lines changed

package-lock.json

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"lint": "next lint"
1010
},
1111
"dependencies": {
12+
"@next-auth/prisma-adapter": "^1.0.5",
1213
"@next/font": "13.1.1",
1314
"@prisma/client": "^4.8.1",
1415
"@types/node": "18.11.18",

pages/api/auth/[...nextauth].ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1+
import { PrismaAdapter } from "@next-auth/prisma-adapter";
12
import NextAuth from "next-auth";
23
import GithubProvider from "next-auth/providers/github";
4+
import DiscordProvider from "next-auth/providers/discord";
5+
import prisma from "prisma/prismaclient";
6+
37
export const authOptions = {
4-
// Configure one or more authentication providers
8+
adapter: PrismaAdapter(prisma),
59
providers: [
610
GithubProvider({
711
clientId: process.env.GITHUB_ID || "",
812
clientSecret: process.env.GITHUB_SECRET || "",
913
}),
10-
// ...add more providers here
14+
DiscordProvider({
15+
clientId: process.env.DISCORD_CLIENT_ID || "",
16+
clientSecret: process.env.DISCORD_CLIENT_SECRET || "",
17+
}),
1118
],
1219
};
1320
export default NextAuth(authOptions);

prisma/prismaclient.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { PrismaClient } from "@prisma/client";
2+
3+
declare global {
4+
var prisma: PrismaClient | undefined;
5+
}
6+
7+
const client = globalThis.prisma || new PrismaClient();
8+
if (process.env.NODE_ENV !== "production") globalThis.prisma = client;
9+
10+
export default client;

prisma/schema.prisma

+44-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,49 @@ datasource db {
1010
url = env("DATABASE_URL")
1111
}
1212

13+
// NextAuth Models
14+
15+
model Account {
16+
id String @id @default(cuid())
17+
userId String
18+
type String
19+
provider String
20+
providerAccountId String
21+
refresh_token String? @db.Text
22+
access_token String? @db.Text
23+
expires_at Int?
24+
token_type String?
25+
scope String?
26+
id_token String? @db.Text
27+
session_state String?
28+
29+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
30+
31+
@@unique([provider, providerAccountId])
32+
}
33+
34+
model Session {
35+
id String @id @default(cuid())
36+
sessionToken String @unique
37+
userId String
38+
expires DateTime
39+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
40+
}
41+
1342
model User {
14-
id Int @id @default(autoincrement())
15-
name String? @db.VarChar(255)
16-
email String @unique @db.VarChar(255)
43+
id String @id @default(cuid())
44+
name String?
45+
email String? @unique
46+
emailVerified DateTime?
47+
image String?
48+
accounts Account[]
49+
sessions Session[]
50+
}
51+
52+
model VerificationToken {
53+
identifier String
54+
token String @unique
55+
expires DateTime
56+
57+
@@unique([identifier, token])
1758
}

tsconfig.json

+19-18
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
{
2-
"compilerOptions": {
3-
"target": "es5",
4-
"lib": ["dom", "dom.iterable", "esnext"],
5-
"allowJs": true,
6-
"skipLibCheck": true,
7-
"strict": true,
8-
"forceConsistentCasingInFileNames": true,
9-
"noEmit": true,
10-
"esModuleInterop": true,
11-
"module": "esnext",
12-
"moduleResolution": "node",
13-
"resolveJsonModule": true,
14-
"isolatedModules": true,
15-
"jsx": "preserve",
16-
"incremental": true
17-
},
18-
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
19-
"exclude": ["node_modules"]
2+
"compilerOptions": {
3+
"target": "es5",
4+
"baseUrl": ".",
5+
"lib": ["dom", "dom.iterable", "esnext"],
6+
"allowJs": true,
7+
"skipLibCheck": true,
8+
"strict": true,
9+
"forceConsistentCasingInFileNames": true,
10+
"noEmit": true,
11+
"esModuleInterop": true,
12+
"module": "esnext",
13+
"moduleResolution": "node",
14+
"resolveJsonModule": true,
15+
"isolatedModules": true,
16+
"jsx": "preserve",
17+
"incremental": true
18+
},
19+
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
20+
"exclude": ["node_modules"]
2021
}

0 commit comments

Comments
 (0)