diff --git a/Websites/jefes-nextjs/app/api/auth/[...nextauth]/route.ts b/Websites/jefes-nextjs/app/api/auth/[...nextauth]/route.ts index ba73b66..c626176 100644 --- a/Websites/jefes-nextjs/app/api/auth/[...nextauth]/route.ts +++ b/Websites/jefes-nextjs/app/api/auth/[...nextauth]/route.ts @@ -11,8 +11,8 @@ const handler = NextAuth({ // e.g. domain, username, password, 2FA token, etc. // You can pass any HTML attribute to the tag through the object. credentials: { - username: { label: "Username", type: "text", placeholder: "jsmith" }, - password: { label: "Password", type: "password" }, + email: {}, + password: {}, }, async authorize(credentials, req) { // Add logic here to look up the user from the credentials supplied @@ -32,4 +32,4 @@ const handler = NextAuth({ ], }); -export {handler as GET, handler as POST}; \ No newline at end of file +export { handler as GET, handler as POST }; diff --git a/Websites/jefes-nextjs/app/api/auth/register/route.ts b/Websites/jefes-nextjs/app/api/auth/register/route.ts index d74b721..d9f59f8 100644 --- a/Websites/jefes-nextjs/app/api/auth/register/route.ts +++ b/Websites/jefes-nextjs/app/api/auth/register/route.ts @@ -2,25 +2,35 @@ import { hash } from "bcrypt"; import "dotenv/config"; import { db, connection } from "@/db/db"; import { users } from "@/db/schema"; +import { NextResponse } from "next/server"; -export default async function POST(request: Request) { +export async function POST(request: Request) { try { const { email, password } = await request.json(); - // validate email and password - if (email != process.env.ADMIN_EMAIL && password != process.env.ADMIN_PWD) { - return 0; + // validate email and password(temporarily hard coded) + if ( + email === process.env.ADMIN_EMAIL && + password === process.env.ADMIN_PWD + ) { + console.log({ message: "success!" }); + console.log({ email, password }); + } + // return if not admin + else { + console.log({ message: "Incorrect credentials for admin!" }); + console.log({ email, password }); + return NextResponse.json({ message: "failed" }); } - console.log({ email, password }); const hashedPassword = await hash(password, 10); + // console.log({message:'hash is', hashedPassword}) const response = await db.insert(users).values({ email: email, password: password, }); - - } catch (e) { console.log({ e }); } + return NextResponse.json({ message: "pass" }); } diff --git a/Websites/jefes-nextjs/app/register/page.tsx b/Websites/jefes-nextjs/app/register/page.tsx index 74d48a4..0d50087 100644 --- a/Websites/jefes-nextjs/app/register/page.tsx +++ b/Websites/jefes-nextjs/app/register/page.tsx @@ -1,28 +1,12 @@ -import React, { FormEvent } from "react"; -import { Input } from "@/components/ui/input"; -import { Button } from "@/components/ui/button"; +import React from "react"; +import RegistrationForm from "./registrationForm"; export default async function Admin() { - const handleSubmit = async (e: FormEvent) => { - e.preventDefault(); - const formData = new FormData(e.currentTarget); - const response = await fetch(`/api/auth/register`, { - method: "POST", - body: JSON.stringify({ - email: formData.get("email"), - password: formData.get("password"), - }), - }); - console.log({ response }); - }; return ( -
- - - -
+
+
+ +
+
); } diff --git a/Websites/jefes-nextjs/app/register/registrationForm.tsx b/Websites/jefes-nextjs/app/register/registrationForm.tsx new file mode 100644 index 0000000..fb8404a --- /dev/null +++ b/Websites/jefes-nextjs/app/register/registrationForm.tsx @@ -0,0 +1,33 @@ +"use client"; +import React, { FormEvent } from "react"; +import { Input } from "@/components/ui/input"; +import { Button } from "@/components/ui/button"; + +const RegistrationForm = () => { + const handleSubmit = async (e: FormEvent) => { + e.preventDefault(); + const formData = new FormData(e.currentTarget); + const response = await fetch(`/api/auth/register`, { + method: "POST", + body: JSON.stringify({ + email: formData.get("email"), + password: formData.get("password"), + }), + }); + console.log({ response }); + }; + return ( +
+
+ + + +
+
+ ); +}; + +export default RegistrationForm;