From 38159b90c18628466009eb0dbb0319afec495179 Mon Sep 17 00:00:00 2001 From: Eric Date: Thu, 10 Nov 2022 15:40:00 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20=E2=9A=A1=EF=B8=8F=20add?= =?UTF-8?q?=20-=20ajout=20d'une=20page=20mon=20compte=20connecter=20a=20la?= =?UTF-8?q?=20bdd=20+=20=20API=20+=20routes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/launch.json | 32 ++++ components/Header.tsx | 7 +- pages/api/auth/[...nextauth].ts | 12 +- pages/api/profile/index.ts | 33 +++++ pages/profile.tsx | 139 ++++++++++++++++++ prisma/dev.db | Bin 57344 -> 65536 bytes .../migrations/20221110093840_/migration.sql | 10 ++ .../migrations/20221110112827_/migration.sql | 21 +++ .../migrations/20221110113201_/migration.sql | 21 +++ prisma/schema.prisma | 26 ++-- types/post.ts | 10 ++ types/profile.ts | 8 + 12 files changed, 303 insertions(+), 16 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 pages/api/profile/index.ts create mode 100644 pages/profile.tsx create mode 100644 prisma/migrations/20221110093840_/migration.sql create mode 100644 prisma/migrations/20221110112827_/migration.sql create mode 100644 prisma/migrations/20221110113201_/migration.sql create mode 100644 types/post.ts create mode 100644 types/profile.ts diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..55bca7e --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,32 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Next.js: debug server-side", + "type": "node-terminal", + "request": "launch", + "command": "npm run dev" + }, + { + "name": "Next.js: debug client-side", + "type": "chrome", + "request": "launch", + "url": "http://localhost:3000" + }, + { + "type": "node", + "request": "launch", + "name": "Launch Program", + "skipFiles": [ + "/**" + ], + "program": "${workspaceFolder}\\pages\\moncompte.tsx", + "outFiles": [ + "${workspaceFolder}/**/*.js" + ] + } + ] +} \ No newline at end of file diff --git a/components/Header.tsx b/components/Header.tsx index 5832e00..142795d 100644 --- a/components/Header.tsx +++ b/components/Header.tsx @@ -8,7 +8,7 @@ const Header = () => { const isActive: (pathname: string) => boolean = (pathname) => router.pathname === pathname; - const {data: session, status} = useSession(); + const { data: session, status } = useSession(); let left = (
@@ -124,6 +124,11 @@ const Header = () => { My drafts + + + Mon Compte + + + + ); +}; + +export default Profil; diff --git a/prisma/dev.db b/prisma/dev.db index b8b0f7148781eb1762d2920adb56a46d8b6b909f..4324548310469bd5a4605a6ffae85a26d83106ad 100644 GIT binary patch delta 3240 zcma)8U5Mk>6}H!&B%awB?UICLJ54hzfhIJbxmW*cNQnGzk0o33pJWJwer?&3?6GCb zHU;lAp-*keGB2fXr7t0nly)A{hd>Jrv=1RP4-IMQLnx&`DQ%jUP-s|sHM5&-DQ#9* z!sl@BcfRx8d(XKyf10>?Gx_rFRWTNeT|w{N=iysV6PLxre5ug*|u;?#55H9N)AS^~uO~T^We4J-S~^^K+|38&cym;_dFhU2ffK>s`<~R zpI+a5?or(t-Pmj9mFCl%d+50UJUvKVKXp=2(1skYnWRRLwn;)j+N4J5xM^zyXPGRiQxr)- z!om%};kt!eB%}?3WHi>Y4AP9hr2X$0E@GRX)p{9Q93vv zfd-KcO-PZf!7>IxF!6Q72Ha%>AM}}i;h$E!54G1Gm(iW3uY0XX> zxXF+@LlHEELjZNoWLb{WIg+$&mey^X(iB<|}^7*-KN6dF_$FR4tZ(#>Jw-NKd?VR0y?t%Eu2KHtQ`yKWP z_ABfc*qdip_g=-s&5guv>duMTN+uplO|9wF8Tr$#1Tr+k7|r}(nu;f`#iL_8O(OVI zsy>&V88=Qr9bG2UwbfeSYr#ha&*N#dRI=yms!Sdy!*^vSCZshWkf8-Evc_axslJPqE{W$N;Ava;CS3DNTGN*=!m7|k-^p_eNvOcg($L+I`I$U-SZNS?TL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`W~JB1wtU*I|15>AC9VPDt@)0sEI{hrP^5{DDm@%>q6gaq|W zXs68@0$n4#5FzK?9~BN89U%$s23}pv~BqIWF-O#g;Xllog`5j&2awQ8hyFinBOh*xpT~V(^`U+XFj$ z5o)nyn^z0L5wzeV{D8M~OxNIAiWzRd_&F)|GLyxBBWZqkKOO@*KGW~u!8rG?EksJ% Qh_-0OO_-SEx&KM%H~rWHVgLXD diff --git a/prisma/migrations/20221110093840_/migration.sql b/prisma/migrations/20221110093840_/migration.sql new file mode 100644 index 0000000..276bf9b --- /dev/null +++ b/prisma/migrations/20221110093840_/migration.sql @@ -0,0 +1,10 @@ +-- CreateTable +CREATE TABLE "Profile" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "bio" TEXT, + "userId" INTEGER NOT NULL, + CONSTRAINT "Profile_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users" ("id") ON DELETE RESTRICT ON UPDATE CASCADE +); + +-- CreateIndex +CREATE UNIQUE INDEX "Profile_userId_key" ON "Profile"("userId"); diff --git a/prisma/migrations/20221110112827_/migration.sql b/prisma/migrations/20221110112827_/migration.sql new file mode 100644 index 0000000..ed4acf4 --- /dev/null +++ b/prisma/migrations/20221110112827_/migration.sql @@ -0,0 +1,21 @@ +/* + Warnings: + + - You are about to drop the `Profile` table. If the table is not empty, all the data it contains will be lost. + +*/ +-- DropTable +PRAGMA foreign_keys=off; +DROP TABLE "Profile"; +PRAGMA foreign_keys=on; + +-- CreateTable +CREATE TABLE "Profil" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "bio" TEXT, + "userId" INTEGER NOT NULL, + CONSTRAINT "Profil_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users" ("id") ON DELETE RESTRICT ON UPDATE CASCADE +); + +-- CreateIndex +CREATE UNIQUE INDEX "Profil_userId_key" ON "Profil"("userId"); diff --git a/prisma/migrations/20221110113201_/migration.sql b/prisma/migrations/20221110113201_/migration.sql new file mode 100644 index 0000000..25b5ab9 --- /dev/null +++ b/prisma/migrations/20221110113201_/migration.sql @@ -0,0 +1,21 @@ +/* + Warnings: + + - You are about to drop the `Profil` table. If the table is not empty, all the data it contains will be lost. + +*/ +-- DropTable +PRAGMA foreign_keys=off; +DROP TABLE "Profil"; +PRAGMA foreign_keys=on; + +-- CreateTable +CREATE TABLE "Profile" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "bio" TEXT, + "userId" INTEGER NOT NULL, + CONSTRAINT "Profile_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users" ("id") ON DELETE RESTRICT ON UPDATE CASCADE +); + +-- CreateIndex +CREATE UNIQUE INDEX "Profile_userId_key" ON "Profile"("userId"); diff --git a/prisma/schema.prisma b/prisma/schema.prisma index abc25bb..cbbd836 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -7,15 +7,6 @@ datasource db { url = "file:./dev.db" } -model Post { - id Int @id @default(autoincrement()) - title String - content String? - published Boolean @default(false) - author User? @relation(fields: [authorId], references: [id]) - authorId Int? -} - model Account { id Int @id @default(autoincrement()) userId Int @map("user_id") @@ -59,10 +50,27 @@ model User { posts Post[] accounts Account[] sessions Session[] + profile Profile? @@map(name: "users") } +model Post { + id Int @id @default(autoincrement()) + title String + content String? + published Boolean @default(false) + author User? @relation(fields: [authorId], references: [id]) + authorId Int? +} + +model Profile { + id Int @id @default(autoincrement()) + bio String? + user User? @relation(fields: [userId], references: [id]) + userId Int @unique +} + model VerificationToken { identifier String token String @unique diff --git a/types/post.ts b/types/post.ts new file mode 100644 index 0000000..ff36e2d --- /dev/null +++ b/types/post.ts @@ -0,0 +1,10 @@ +export type PostProps = { + id: number; + title: string; + author: { + name: string; + email: string; + } | null; + content: string; + published: boolean; + }; \ No newline at end of file diff --git a/types/profile.ts b/types/profile.ts new file mode 100644 index 0000000..e42f395 --- /dev/null +++ b/types/profile.ts @@ -0,0 +1,8 @@ +export type ProfileProps = { + id: number; + bio: string; + user: { + name: string; + email: string; + } +}; \ No newline at end of file