Skip to content

Commit 48de926

Browse files
authored
🗃️ Prisma for auth
1 parent fb7db77 commit 48de926

File tree

10 files changed

+167
-97
lines changed

10 files changed

+167
-97
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ yarn-error.log*
2929
.env.development.local
3030
.env.test.local
3131
.env.production.local
32+
.env
3233

3334
# vercel
3435
.vercel

lib/auth0.js

-24
This file was deleted.

lib/prisma.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { PrismaClient } from '@prisma/client'
2+
3+
const prisma = new PrismaClient()
4+
5+
export default prisma

lib/user.js

-73
This file was deleted.

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
"@emotion/react": "^11",
1616
"@emotion/styled": "^11",
1717
"@fontsource/inter": "^4.5.0",
18+
"@next-auth/prisma-adapter": "^1.0.3",
1819
"@octokit/rest": "^18.12.0",
20+
"@prisma/client": "^3.14.0",
1921
"axios": "^0.24.0",
2022
"chakra-ui-steps": "^1.5.0",
2123
"framer-motion": "^4",
@@ -29,6 +31,7 @@
2931
"devDependencies": {
3032
"eslint": "7.32.0",
3133
"eslint-config-next": "11.1.2",
34+
"prisma": "^3.14.0",
3235
"typescript": "^4.6.4"
3336
}
3437
}

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

+3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
// pages/api/auth/[...nextauth.js]
2+
import { PrismaAdapter } from "@next-auth/prisma-adapter";
23
import NextAuth from "next-auth"
34
import GithubProvider from "next-auth/providers/github"
5+
import prisma from "../../../lib/prisma";
46

57
export default NextAuth({
8+
adapter: PrismaAdapter(prisma),
69
// Configure one or more authentication providers
710
debug: false,
811
jwt: {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
-- CreateTable
2+
CREATE TABLE "Account" (
3+
"id" TEXT NOT NULL,
4+
"userId" TEXT NOT NULL,
5+
"type" TEXT NOT NULL,
6+
"provider" TEXT NOT NULL,
7+
"providerAccountId" TEXT NOT NULL,
8+
"refresh_token" TEXT,
9+
"access_token" TEXT,
10+
"expires_at" INTEGER,
11+
"token_type" TEXT,
12+
"scope" TEXT,
13+
"id_token" TEXT,
14+
"session_state" TEXT,
15+
16+
CONSTRAINT "Account_pkey" PRIMARY KEY ("id")
17+
);
18+
19+
-- CreateTable
20+
CREATE TABLE "Session" (
21+
"id" TEXT NOT NULL,
22+
"sessionToken" TEXT NOT NULL,
23+
"userId" TEXT NOT NULL,
24+
"expires" TIMESTAMP(3) NOT NULL,
25+
26+
CONSTRAINT "Session_pkey" PRIMARY KEY ("id")
27+
);
28+
29+
-- CreateTable
30+
CREATE TABLE "User" (
31+
"id" TEXT NOT NULL,
32+
"name" TEXT,
33+
"email" TEXT,
34+
"emailVerified" TIMESTAMP(3),
35+
"image" TEXT,
36+
37+
CONSTRAINT "User_pkey" PRIMARY KEY ("id")
38+
);
39+
40+
-- CreateTable
41+
CREATE TABLE "VerificationToken" (
42+
"identifier" TEXT NOT NULL,
43+
"token" TEXT NOT NULL,
44+
"expires" TIMESTAMP(3) NOT NULL
45+
);
46+
47+
-- CreateIndex
48+
CREATE UNIQUE INDEX "Account_provider_providerAccountId_key" ON "Account"("provider", "providerAccountId");
49+
50+
-- CreateIndex
51+
CREATE UNIQUE INDEX "Session_sessionToken_key" ON "Session"("sessionToken");
52+
53+
-- CreateIndex
54+
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");
55+
56+
-- CreateIndex
57+
CREATE UNIQUE INDEX "VerificationToken_token_key" ON "VerificationToken"("token");
58+
59+
-- CreateIndex
60+
CREATE UNIQUE INDEX "VerificationToken_identifier_token_key" ON "VerificationToken"("identifier", "token");
61+
62+
-- AddForeignKey
63+
ALTER TABLE "Account" ADD CONSTRAINT "Account_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
64+
65+
-- AddForeignKey
66+
ALTER TABLE "Session" ADD CONSTRAINT "Session_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

prisma/migrations/migration_lock.toml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Please do not edit this file manually
2+
# It should be added in your version-control system (i.e. Git)
3+
provider = "postgresql"

prisma/schema.prisma

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// This is your Prisma schema file,
2+
// learn more about it in the docs: https://pris.ly/d/prisma-schema
3+
4+
generator client {
5+
provider = "prisma-client-js"
6+
}
7+
8+
datasource db {
9+
provider = "postgresql"
10+
url = env("DB")
11+
shadowDatabaseUrl = env("DB_SHADOW")
12+
}
13+
14+
model Account {
15+
id String @id @default(cuid())
16+
userId String
17+
type String
18+
provider String
19+
providerAccountId String
20+
refresh_token String? @db.Text
21+
access_token String? @db.Text
22+
expires_at Int?
23+
token_type String?
24+
scope String?
25+
id_token String? @db.Text
26+
session_state String?
27+
28+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
29+
30+
@@unique([provider, providerAccountId])
31+
}
32+
33+
model Session {
34+
id String @id @default(cuid())
35+
sessionToken String @unique
36+
userId String
37+
expires DateTime
38+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
39+
}
40+
41+
model User {
42+
id String @id @default(cuid())
43+
name String?
44+
email String? @unique
45+
emailVerified DateTime?
46+
image String?
47+
accounts Account[]
48+
sessions Session[]
49+
}
50+
51+
model VerificationToken {
52+
identifier String
53+
token String @unique
54+
expires DateTime
55+
56+
@@unique([identifier, token])
57+
}

yarn.lock

+29
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,11 @@
849849
resolved "https://registry.yarnpkg.com/@napi-rs/triples/-/triples-1.0.3.tgz#76d6d0c3f4d16013c61e45dfca5ff1e6c31ae53c"
850850
integrity sha512-jDJTpta+P4p1NZTFVLHJ/TLFVYVcOqv6l8xwOeBKNPMgY/zDYH/YH7SJbvrr/h1RcS9GzbPcLKGzpuK9cV56UA==
851851

852+
"@next-auth/prisma-adapter@^1.0.3":
853+
version "1.0.3"
854+
resolved "https://registry.yarnpkg.com/@next-auth/prisma-adapter/-/prisma-adapter-1.0.3.tgz#cd6b866a3e281370ce64aa67daf320322a42a2b9"
855+
integrity sha512-3Lq1cD3ytKM3EGKJZ4UZvlqshLtlPvYxLeCrUV9ifYwYlq51kmDaHjsIawlp8EbH5pE1UhlsvtlXMery7RghtA==
856+
852857
853858
version "11.1.2"
854859
resolved "https://registry.yarnpkg.com/@next/env/-/env-11.1.2.tgz#27996efbbc54c5f949f5e8c0a156e3aa48369b99"
@@ -1052,6 +1057,23 @@
10521057
resolved "https://registry.yarnpkg.com/@popperjs/core/-/core-2.4.4.tgz#11d5db19bd178936ec89cd84519c4de439574398"
10531058
integrity sha512-1oO6+dN5kdIA3sKPZhRGJTfGVP4SWV6KqlMOwry4J3HfyD68sl/3KmG7DeYUzvN+RbhXDnv/D8vNNB8168tAMg==
10541059

1060+
"@prisma/client@^3.14.0":
1061+
version "3.14.0"
1062+
resolved "https://registry.yarnpkg.com/@prisma/client/-/client-3.14.0.tgz#bb90405c012fcca11f4647d91153ed4c58f3bd48"
1063+
integrity sha512-atb41UpgTR1MCst0VIbiHTMw8lmXnwUvE1KyUCAkq08+wJyjRE78Due+nSf+7uwqQn+fBFYVmoojtinhlLOSaA==
1064+
dependencies:
1065+
"@prisma/engines-version" "3.14.0-36.2b0c12756921c891fec4f68d9444e18c7d5d4a6a"
1066+
1067+
"@prisma/engines-version@3.14.0-36.2b0c12756921c891fec4f68d9444e18c7d5d4a6a":
1068+
version "3.14.0-36.2b0c12756921c891fec4f68d9444e18c7d5d4a6a"
1069+
resolved "https://registry.yarnpkg.com/@prisma/engines-version/-/engines-version-3.14.0-36.2b0c12756921c891fec4f68d9444e18c7d5d4a6a.tgz#4edae57cf6527f35e22cebe75e49214fc0e99ac9"
1070+
integrity sha512-D+yHzq4a2r2Rrd0ZOW/mTZbgDIkUkD8ofKgusEI1xPiZz60Daks+UM7Me2ty5FzH3p/TgyhBpRrfIHx+ha20RQ==
1071+
1072+
1073+
version "3.14.0-36.2b0c12756921c891fec4f68d9444e18c7d5d4a6a"
1074+
resolved "https://registry.yarnpkg.com/@prisma/engines/-/engines-3.14.0-36.2b0c12756921c891fec4f68d9444e18c7d5d4a6a.tgz#7fa11bc26a51d450185c816cc0ab8cac673fb4bf"
1075+
integrity sha512-LwZvI3FY6f43xFjQNRuE10JM5R8vJzFTSmbV9X0Wuhv9kscLkjRlZt0BEoiHmO+2HA3B3xxbMfB5du7ZoSFXGg==
1076+
10551077
10561078
version "0.13.2"
10571079
resolved "https://registry.yarnpkg.com/@reach/alert/-/alert-0.13.2.tgz#71c4a848d51341f1d6d9eaae060975391c224870"
@@ -3810,6 +3832,13 @@ pretty-format@^3.8.0:
38103832
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-3.8.0.tgz#bfbed56d5e9a776645f4b1ff7aa1a3ac4fa3c385"
38113833
integrity sha1-v77VbV6ad2ZF9LH/eqGjrE+jw4U=
38123834

3835+
prisma@^3.14.0:
3836+
version "3.14.0"
3837+
resolved "https://registry.yarnpkg.com/prisma/-/prisma-3.14.0.tgz#dd67ece37d7b5373e9fd9588971de0024b49be81"
3838+
integrity sha512-l9MOgNCn/paDE+i1K2fp9NZ+Du4trzPTJsGkaQHVBufTGqzoYHuNk8JfzXuIn0Gte6/ZjyKj652Jq/Lc1tp2yw==
3839+
dependencies:
3840+
"@prisma/engines" "3.14.0-36.2b0c12756921c891fec4f68d9444e18c7d5d4a6a"
3841+
38133842
process-nextick-args@~2.0.0:
38143843
version "2.0.1"
38153844
resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2"

0 commit comments

Comments
 (0)