diff --git a/Websites/jefes-nextjs/.env b/Websites/jefes-nextjs/.env index 04286d9..2c5f396 100644 --- a/Websites/jefes-nextjs/.env +++ b/Websites/jefes-nextjs/.env @@ -12,4 +12,6 @@ DB_HOST="aws.connect.psdb.cloud" DB_USER="11lq0wcjbxyku4zmubji" DB_PASSWORD="pscale_pw_AyxGMWCMpaZOsaeeXXem8mrxXPRNJEG0uPUrW2zo1f8" DB_NAME="dev_db" -DB_URI="mysql://11lq0wcjbxyku4zmubji:pscale_pw_AyxGMWCMpaZOsaeeXXem8mrxXPRNJEG0uPUrW2zo1f8@aws.connect.psdb.cloud/dev_db?ssl={"rejectUnauthorized":true}" \ No newline at end of file +DB_URI="mysql://11lq0wcjbxyku4zmubji:pscale_pw_AyxGMWCMpaZOsaeeXXem8mrxXPRNJEG0uPUrW2zo1f8@aws.connect.psdb.cloud/dev_db?ssl={"rejectUnauthorized":true}" +ADMIN_EMAIL="Kevin@test.com" +ADMIN_PWD="!Testingpwd123" \ No newline at end of file diff --git a/Websites/jefes-nextjs/app/admin/page.tsx b/Websites/jefes-nextjs/app/admin/page.tsx new file mode 100644 index 0000000..56546b8 --- /dev/null +++ b/Websites/jefes-nextjs/app/admin/page.tsx @@ -0,0 +1,28 @@ +import React, { FormEvent } from "react"; +import { Input } from "@/components/ui/input"; +import { Button } from "@/components/ui/button"; + +export default async function Admin() { + const handleSubmit = async (e: FormEvent) => { + e.preventDefault(); + const formData = new FormData(e.currentTarget); + const response = await fetch(`/api/auth/admin`, { + method: "POST", + body: JSON.stringify({ + email: formData.get("email"), + password: formData.get("password"), + }), + }); + console.log({ response }); + }; + return ( +
+ + + +
+ ); +} diff --git a/Websites/jefes-nextjs/app/api/auth/[...nextauth]/route.ts b/Websites/jefes-nextjs/app/api/auth/[...nextauth]/route.ts index cc3e5d8..ba73b66 100644 --- a/Websites/jefes-nextjs/app/api/auth/[...nextauth]/route.ts +++ b/Websites/jefes-nextjs/app/api/auth/[...nextauth]/route.ts @@ -1,3 +1,35 @@ -import { handlers } from "@/app/auth"; +import NextAuth from "next-auth"; +import CredentialsProvider from "next-auth/providers/credentials"; -export const {GET, POST } = handlers \ No newline at end of file +const handler = NextAuth({ + providers: [ + CredentialsProvider({ + // The name to display on the sign in form (e.g. "Sign in with...") + name: "Credentials", + // `credentials` is used to generate a form on the sign in page. + // You can specify which fields should be submitted, by adding keys to the `credentials` object. + // 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" }, + }, + async authorize(credentials, req) { + // Add logic here to look up the user from the credentials supplied + const user = { id: "1", name: "J Smith", email: "jsmith@example.com" }; + + if (user) { + // Any object returned will be saved in `user` property of the JWT + return user; + } else { + // If you return null then an error will be displayed advising the user to check their details. + return null; + + // You can also Reject this callback with an Error thus the user will be sent to the error page with the error message as a query parameter + } + }, + }), + ], +}); + +export {handler as GET, handler as POST}; \ No newline at end of file diff --git a/Websites/jefes-nextjs/app/api/auth/admin/route.ts b/Websites/jefes-nextjs/app/api/auth/admin/route.ts new file mode 100644 index 0000000..9f84833 --- /dev/null +++ b/Websites/jefes-nextjs/app/api/auth/admin/route.ts @@ -0,0 +1,14 @@ +import "dotenv/config"; + +export default 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; + } + console.log({ email, password }); + } catch (e) { + console.log({ e }); + } +} diff --git a/Websites/jefes-nextjs/app/api/auth/register/route.ts b/Websites/jefes-nextjs/app/api/auth/register/route.ts new file mode 100644 index 0000000..d74b721 --- /dev/null +++ b/Websites/jefes-nextjs/app/api/auth/register/route.ts @@ -0,0 +1,26 @@ +import { hash } from "bcrypt"; +import "dotenv/config"; +import { db, connection } from "@/db/db"; +import { users } from "@/db/schema"; + +export default 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; + } + console.log({ email, password }); + + const hashedPassword = await hash(password, 10); + + const response = await db.insert(users).values({ + email: email, + password: password, + }); + + + } catch (e) { + console.log({ e }); + } +} diff --git a/Websites/jefes-nextjs/app/components/NavBar/NavBar.tsx b/Websites/jefes-nextjs/app/components/NavBar/NavBar.tsx index 81918be..08f1819 100644 --- a/Websites/jefes-nextjs/app/components/NavBar/NavBar.tsx +++ b/Websites/jefes-nextjs/app/components/NavBar/NavBar.tsx @@ -160,8 +160,8 @@ const NavBar = () => {