From 855531a67c78546416c77b7787341709d47f61d1 Mon Sep 17 00:00:00 2001 From: Jason Diaz Jimenez Date: Thu, 7 Sep 2023 22:54:49 -0500 Subject: [PATCH] Removed Prisma and Fixed Footer --- apps/website/package.json | 2 - .../src/app/api/auth/[...nextauth]/route.ts | 50 -------------- apps/website/src/app/api/register/route.ts | 49 ------------- apps/website/src/app/signin/SignInForm.tsx | 28 ++++---- apps/website/src/app/signin/page.tsx | 6 +- apps/website/src/app/signup/page.tsx | 28 ++++---- apps/website/src/components/base/Footer.tsx | 2 +- apps/website/src/context/Providers.tsx | 6 +- yarn.lock | 68 ++----------------- 9 files changed, 43 insertions(+), 196 deletions(-) delete mode 100644 apps/website/src/app/api/auth/[...nextauth]/route.ts delete mode 100644 apps/website/src/app/api/register/route.ts diff --git a/apps/website/package.json b/apps/website/package.json index 993ce8cc..85e3d753 100644 --- a/apps/website/package.json +++ b/apps/website/package.json @@ -16,7 +16,6 @@ "@fortawesome/free-brands-svg-icons": "^6.4.0", "@fortawesome/react-fontawesome": "^0.2.0", "@headlessui/react": "^1.7.17", - "@prisma/client": "^4.16.2", "@tailwindcss/forms": "^0.5.5", "@tailwindcss/typography": "^0.5.9", "@types/lodash-es": "^4.17.8", @@ -32,7 +31,6 @@ "lodash.kebabcase": "^4.1.1", "lucide-react": "^0.269.0", "next": "^13.4.19", - "next-auth": "^4.22.3", "postcss": "^8.4.28", "react": "^18.2.0", "react-dom": "^18.2.0", diff --git a/apps/website/src/app/api/auth/[...nextauth]/route.ts b/apps/website/src/app/api/auth/[...nextauth]/route.ts deleted file mode 100644 index e81ebfc4..00000000 --- a/apps/website/src/app/api/auth/[...nextauth]/route.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { AuthOptions } from "next-auth" -import Credentials from "next-auth/providers/credentials" -import { PrismaAdapter } from "@auth/prisma-adapter" -import { PrismaClient } from "@prisma/client" -import { compare } from "bcrypt" -import NextAuth from "next-auth/next" - -const prisma = new PrismaClient() - -const authOption: AuthOptions = { - // @ts-expect-error - adapter: PrismaAdapter(prisma), - providers: [ - Credentials({ - name: "credentials", - credentials: { - email: { label: "Email", type: "email" }, - password: { label: "Password", type: "password" } - }, - async authorize(credentials) { - if (!credentials || !credentials.email || !credentials.password) { - return null - } - const user = await (prisma as any).user.findUnique({ - where: { - email: credentials.email - } - }) - if (!user) { - return null - } - const passwordMatch = await compare(credentials.password, user.password) - - if (!passwordMatch) { - return null - } - - return user - } - }) - ], - secret: process.env.SECRET, - session: { - strategy: "jwt" - } -} - -const handler = NextAuth(authOption) - -export { handler as POST, handler as GET } diff --git a/apps/website/src/app/api/register/route.ts b/apps/website/src/app/api/register/route.ts deleted file mode 100644 index fc95d2d3..00000000 --- a/apps/website/src/app/api/register/route.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { PrismaClient } from "@prisma/client" -import { NextRequest, NextResponse } from "next/server" -import { hash } from "bcrypt" - -const prisma = new PrismaClient() - -export async function POST(request: NextRequest) { - const body = await request.json() - const { username: displayName, email, password } = body - - if (!displayName || !email || !password) { - return new NextResponse("Email and password are required", { status: 400 }) - } - - const user = await (prisma as any).user.findUnique({ - where: { - email: email - } - }) - - const username = (displayName as string).toLowerCase().split(" ").join("-") - const usernameTaken = await (prisma as any).user.findUnique({ - where: { - username: username - } - }) - - if (user) { - return new NextResponse("Email already exists", { status: 400 }) - } - - if (usernameTaken) { - return new NextResponse("Username is already taken", { status: 400 }) - } - - const hashedPassword = await hash(password, 10) - console.log({ email, password }) - - const createdUser = await (prisma as any).user.create({ - data: { - displayName: displayName, - username: username, - email, - password: hashedPassword - } - }) - - return new NextResponse(JSON.stringify(createdUser)) -} diff --git a/apps/website/src/app/signin/SignInForm.tsx b/apps/website/src/app/signin/SignInForm.tsx index 33b78bb9..212052ec 100644 --- a/apps/website/src/app/signin/SignInForm.tsx +++ b/apps/website/src/app/signin/SignInForm.tsx @@ -3,7 +3,7 @@ import { FormEvent, useEffect, useState } from "react" import { useRouter } from "next/navigation" -import { signIn, useSession } from "next-auth/react" +// import { signIn, useSession } from "next-auth/react" import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" import { emailRegex } from "@/constants" @@ -16,20 +16,20 @@ export default function SignInForm() { // TODO: 2. recommended to create a useClientAuth() custom hook to resolve code dup // TODO: and also sharable for signup form too // !!!!! code duplication detected !!!!! - const { status, data } = useSession() - const router = useRouter() + // const { status, data } = useSession() + // const router = useRouter() const [emailEntered, setEmailEntered] = useState(false) const [errors, setErrors] = useState([]) const [email, setEmail] = useState("") const [password, setPassword] = useState("") - useEffect(() => { - console.log("USE EFFECT ") - if (status === "authenticated" && data) { - console.log("LOGGED") - router.push("/") - } - console.log("NOT LOGGED") - }, [status, data, router]) + // useEffect(() => { + // console.log("USE EFFECT ") + // if (status === "authenticated" && data) { + // console.log("LOGGED") + // router.push("/") + // } + // console.log("NOT LOGGED") + // }, [status, data, router]) // TODO export this function as a custom hook as `useValidateEmail()` so it can be used to the signup page as well const validateEmail = () => { @@ -45,8 +45,8 @@ export default function SignInForm() { const submitLogin = (e: FormEvent) => { e.preventDefault() - signIn("credentials", { email, password, redirect: false }) - router.push("/") + // signIn("credentials", { email, password, redirect: false }) + // router.push("/") } return ( @@ -123,7 +123,7 @@ export default function SignInForm() { value={password} onChange={(e) => setPassword(e.target.value)} /> - + diff --git a/apps/website/src/app/signin/page.tsx b/apps/website/src/app/signin/page.tsx index e15359ea..846ba2be 100644 --- a/apps/website/src/app/signin/page.tsx +++ b/apps/website/src/app/signin/page.tsx @@ -7,5 +7,9 @@ export const metadata: Metadata = { } export default function SignIn() { - return + return ( +
+ +
+ ) } diff --git a/apps/website/src/app/signup/page.tsx b/apps/website/src/app/signup/page.tsx index a752e793..941d2c68 100644 --- a/apps/website/src/app/signup/page.tsx +++ b/apps/website/src/app/signup/page.tsx @@ -34,20 +34,20 @@ export default function SignUp() { const submitRegister = async (e: FormEvent) => { e.preventDefault() - const response = await fetch("/api/register", { - method: "POST", - headers: { - "Content-Type": "application/json" - }, - body: JSON.stringify({ - username: username, - email: email, - password: password - }) - }) - const user = await response.json() - console.log(user) - router.push("/signin") + // const response = await fetch("/api/register", { + // method: "POST", + // headers: { + // "Content-Type": "application/json" + // }, + // body: JSON.stringify({ + // username: username, + // email: email, + // password: password + // }) + // }) + // const user = await response.json() + // console.log(user) + // router.push("/signin") } return ( diff --git a/apps/website/src/components/base/Footer.tsx b/apps/website/src/components/base/Footer.tsx index ef7d1104..36977462 100644 --- a/apps/website/src/components/base/Footer.tsx +++ b/apps/website/src/components/base/Footer.tsx @@ -79,7 +79,7 @@ export default function Footer() { return (