Skip to content

Commit

Permalink
Implement authentication flow
Browse files Browse the repository at this point in the history
  • Loading branch information
bombies committed Oct 25, 2023
1 parent 895e9f9 commit 889548b
Show file tree
Hide file tree
Showing 15 changed files with 350 additions and 64 deletions.
61 changes: 61 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"lint": "next lint"
},
"dependencies": {
"@auth/prisma-adapter": "^1.0.5",
"@nextui-org/react": "^2.1.13",
"@prisma/client": "^5.5.0",
"@theinternetfolks/snowflake": "^1.3.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
Warnings:
- You are about to drop the column `userId` on the `Account` table. All the data in the column will be lost.
*/
-- DropForeignKey
ALTER TABLE "Account" DROP CONSTRAINT "Account_userId_fkey";

-- AlterTable
ALTER TABLE "Account" DROP COLUMN "userId";
17 changes: 17 additions & 0 deletions prisma/migrations/20231025033601_init/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
Warnings:
- You are about to drop the column `avatar` on the `User` table. All the data in the column will be lost.
- Added the required column `userId` to the `Account` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "Account" ADD COLUMN "userId" TEXT NOT NULL;

-- AlterTable
ALTER TABLE "User" DROP COLUMN "avatar",
ADD COLUMN "image" TEXT,
ADD COLUMN "name" TEXT;

-- AddForeignKey
ALTER TABLE "Account" ADD CONSTRAINT "Account_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
94 changes: 94 additions & 0 deletions prisma/migrations/20231025034840_init/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
Warnings:
- You are about to drop the column `accountProvider` on the `User` table. All the data in the column will be lost.
- You are about to drop the column `createdAt` on the `User` table. All the data in the column will be lost.
- You are about to drop the column `firstName` on the `User` table. All the data in the column will be lost.
- You are about to drop the column `lastName` on the `User` table. All the data in the column will be lost.
- You are about to drop the column `password` on the `User` table. All the data in the column will be lost.
- You are about to drop the column `updatedAt` on the `User` table. All the data in the column will be lost.
- You are about to drop the column `username` on the `User` table. All the data in the column will be lost.
*/
-- DropForeignKey
ALTER TABLE "Dream" DROP CONSTRAINT "Dream_userId_fkey";

-- DropForeignKey
ALTER TABLE "DreamCharacter" DROP CONSTRAINT "DreamCharacter_userId_fkey";

-- DropForeignKey
ALTER TABLE "DreamTag" DROP CONSTRAINT "DreamTag_userId_fkey";

-- DropForeignKey
ALTER TABLE "FriendRequest" DROP CONSTRAINT "FriendRequest_reveiverId_fkey";

-- DropForeignKey
ALTER TABLE "FriendRequest" DROP CONSTRAINT "FriendRequest_senderId_fkey";

-- DropForeignKey
ALTER TABLE "UserProfile" DROP CONSTRAINT "UserProfile_userId_fkey";

-- DropForeignKey
ALTER TABLE "_UserFriends" DROP CONSTRAINT "_UserFriends_A_fkey";

-- DropForeignKey
ALTER TABLE "_UserFriends" DROP CONSTRAINT "_UserFriends_B_fkey";

-- DropIndex
DROP INDEX "User_username_key";

-- AlterTable
ALTER TABLE "User" DROP COLUMN "accountProvider",
DROP COLUMN "createdAt",
DROP COLUMN "firstName",
DROP COLUMN "lastName",
DROP COLUMN "password",
DROP COLUMN "updatedAt",
DROP COLUMN "username";

-- CreateTable
CREATE TABLE "Member" (
"id" TEXT NOT NULL,
"name" TEXT,
"email" TEXT NOT NULL,
"password" TEXT,
"image" TEXT,
"accountProvider" "AccountProvider",
"username" TEXT NOT NULL,
"firstName" TEXT NOT NULL,
"lastName" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,

CONSTRAINT "Member_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "Member_email_key" ON "Member"("email");

-- CreateIndex
CREATE UNIQUE INDEX "Member_username_key" ON "Member"("username");

-- AddForeignKey
ALTER TABLE "FriendRequest" ADD CONSTRAINT "FriendRequest_senderId_fkey" FOREIGN KEY ("senderId") REFERENCES "Member"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "FriendRequest" ADD CONSTRAINT "FriendRequest_reveiverId_fkey" FOREIGN KEY ("reveiverId") REFERENCES "Member"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "UserProfile" ADD CONSTRAINT "UserProfile_userId_fkey" FOREIGN KEY ("userId") REFERENCES "Member"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Dream" ADD CONSTRAINT "Dream_userId_fkey" FOREIGN KEY ("userId") REFERENCES "Member"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "DreamTag" ADD CONSTRAINT "DreamTag_userId_fkey" FOREIGN KEY ("userId") REFERENCES "Member"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "DreamCharacter" ADD CONSTRAINT "DreamCharacter_userId_fkey" FOREIGN KEY ("userId") REFERENCES "Member"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_UserFriends" ADD CONSTRAINT "_UserFriends_A_fkey" FOREIGN KEY ("A") REFERENCES "Member"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_UserFriends" ADD CONSTRAINT "_UserFriends_B_fkey" FOREIGN KEY ("B") REFERENCES "Member"("id") ON DELETE CASCADE ON UPDATE CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "User" ADD COLUMN "role" TEXT;
64 changes: 37 additions & 27 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -37,55 +37,65 @@ model Session {
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}

model VerificationToken {
identifier String
token String @unique
expires DateTime
@@unique([identifier, token])
}

enum AccountProvider {
GOOGLE
}

model User {
id String @id @default(cuid())
id String @id @default(cuid())
name String?
role String?
email String @unique
emailVerified DateTime?
image String?
accounts Account[]
sessions Session[]
}

model Member {
id String @id @default(cuid())
name String?
email String @unique
password String?
image String?
accountProvider AccountProvider?
username String @unique
firstName String
lastName String
email String @unique
emailVerified DateTime?
password String?
avatar String?
accountProvider AccountProvider?
accounts Account[]
sessions Session[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
dreams Dream[]
dreamTags DreamTag[]
dreamCharacters DreamCharacter[]
UserProfile UserProfile?
friends User[] @relation("UserFriends")
friends Member[] @relation("UserFriends")
// This fields only exists to satisfy prisma's relationship requiremnts.
friendsOf User[] @relation("UserFriends")
friendsOf Member[] @relation("UserFriends")
sentFriendRequests FriendRequest[] @relation(name: "SentFriendRequests")
friendRequests FriendRequest[] @relation(name: "ReceivedFriendRequests")
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}

model VerificationToken {
identifier String
token String @unique
expires DateTime
@@unique([identifier, token])
}

model FriendRequest {
id String @id @default(cuid())
senderId String
sender User @relation(name: "SentFriendRequests", fields: [senderId], references: [id])
sender Member @relation(name: "SentFriendRequests", fields: [senderId], references: [id])
reveiverId String
receiver User @relation(name: "ReceivedFriendRequests", fields: [reveiverId], references: [id])
receiver Member @relation(name: "ReceivedFriendRequests", fields: [reveiverId], references: [id])
createdAt DateTime @default(now())
}
Expand All @@ -95,7 +105,7 @@ model UserProfile {
bio String?
userId String @unique
user User @relation(fields: [userId], references: [id])
user Member @relation(fields: [userId], references: [id])
}

model Dream {
Expand All @@ -106,7 +116,7 @@ model Dream {
tags DreamTag[]
characters DreamCharacter[]
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
user Member @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String
}

Expand All @@ -116,7 +126,7 @@ model DreamTag {
dreams Dream[]
userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
user Member @relation(fields: [userId], references: [id], onDelete: Cascade)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Expand All @@ -128,7 +138,7 @@ model DreamCharacter {
dreams Dream[]
userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
user Member @relation(fields: [userId], references: [id], onDelete: Cascade)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Expand Down
5 changes: 3 additions & 2 deletions src/app/(site)/components/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ import Button from "@/app/(site)/components/Button";
import clsx from "clsx";
import Image from "@/app/(site)/components/Image";
import {signIn, useSession} from "next-auth/react";
import UserProfile from "@/app/(site)/components/UserProfile";

const NavBar: FC = () => {
const [isMenuOpen, setMenuOpen] = useState(false)
const pathName = usePathname();
const {status: authStatus} = useSession()
const {data: session, status: authStatus} = useSession()

return (
<Navbar
Expand Down Expand Up @@ -75,7 +76,7 @@ const NavBar: FC = () => {
:
(
<Fragment>
{/*TODO: Set up user profile*/}
<UserProfile user={session!!.user!!} />
</Fragment>
)
}
Expand Down
Loading

0 comments on commit 889548b

Please sign in to comment.