From 584e3b349f8a1f379b56d1d3d4489f37aad1fbd1 Mon Sep 17 00:00:00 2001 From: Aaron William Po Date: Sun, 5 Mar 2023 14:07:19 -0500 Subject: [PATCH] Implement confirm user functionality This commit adds the necessary functionality to confirm a user's account. It includes the addition of a new column in the user table to track whether an account is confirmed or not, and the implementation of JWT for confirmation tokens. This commit integrates the SparkPost API as well as React Email to send dynamic emails for whatever purpose. Upon user registration, a confirmation email will be sent to the user. --- .gitignore | 2 +- components/BeerById/BeerInfoHeader.tsx | 2 +- components/ui/Navbar.tsx | 2 +- components/ui/forms/Button.tsx | 2 +- config/auth/session.ts | 10 +- config/jwt/index.ts | 28 + .../nextConnect/middleware/getCurrentUser.ts | 2 +- config/sparkpost/client.ts | 11 + config/sparkpost/sendEmail.ts | 25 + emails/Welcome.tsx | 46 + package-lock.json | 5176 ++++++++++++++++- package.json | 20 +- pages/api/users/confirm.ts | 56 + pages/api/users/register.ts | 19 +- .../migrations/20230304185749_/migration.sql | 2 + prisma/schema.prisma | 35 +- services/User/createNewUser.ts | 1 + services/User/findUserById.ts | 1 + services/User/schema/GetUserSchema.ts | 1 + services/User/sendConfirmationEmail.ts | 32 + services/User/updateUserToBeConfirmedById.ts | 24 + 21 files changed, 5352 insertions(+), 145 deletions(-) create mode 100644 config/jwt/index.ts create mode 100644 config/sparkpost/client.ts create mode 100644 config/sparkpost/sendEmail.ts create mode 100644 emails/Welcome.tsx create mode 100644 pages/api/users/confirm.ts create mode 100644 prisma/migrations/20230304185749_/migration.sql create mode 100644 services/User/sendConfirmationEmail.ts create mode 100644 services/User/updateUserToBeConfirmedById.ts diff --git a/.gitignore b/.gitignore index 26a5e38..49df5aa 100644 --- a/.gitignore +++ b/.gitignore @@ -40,4 +40,4 @@ next-env.d.ts *.http # uploaded images -public/uploads +public/uploads \ No newline at end of file diff --git a/components/BeerById/BeerInfoHeader.tsx b/components/BeerById/BeerInfoHeader.tsx index 66994f5..acb4200 100644 --- a/components/BeerById/BeerInfoHeader.tsx +++ b/components/BeerById/BeerInfoHeader.tsx @@ -59,7 +59,7 @@ const BeerInfoHeader: FC<{ beerPost: BeerPostQueryResult; initialLikeCount: numb
diff --git a/components/ui/Navbar.tsx b/components/ui/Navbar.tsx index 0e69453..4803717 100644 --- a/components/ui/Navbar.tsx +++ b/components/ui/Navbar.tsx @@ -68,7 +68,7 @@ const Navbar = () => {
-
+