diff --git a/frontend/app/(authenticated)/layout.tsx b/frontend/app/(authenticated)/layout.tsx index 93f937d34d..7ab2f1e87c 100644 --- a/frontend/app/(authenticated)/layout.tsx +++ b/frontend/app/(authenticated)/layout.tsx @@ -68,7 +68,7 @@ export default function AuthenticatedLayout({ Username Profile - Log out + Log out diff --git a/frontend/app/forgot-password/page.tsx b/frontend/app/forgot-password/page.tsx index 06ad77cd39..d23086fba2 100644 --- a/frontend/app/forgot-password/page.tsx +++ b/frontend/app/forgot-password/page.tsx @@ -97,7 +97,7 @@ export default function ForgotPassword() {
- +
diff --git a/frontend/app/login/page.tsx b/frontend/app/login/page.tsx new file mode 100644 index 0000000000..110000cb96 --- /dev/null +++ b/frontend/app/login/page.tsx @@ -0,0 +1,161 @@ +"use client" + +import { Button } from "@/components/ui/button"; +import { Input } from "@/components/ui/input"; +import Link from "next/link"; +import { z } from "zod"; +import { useForm } from "react-hook-form"; +import { zodResolver } from "@hookform/resolvers/zod"; +import { + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "@/components/ui/form" +import { useRouter } from "next/navigation" +import { useState } from "react"; +import { AlertCircle, LoaderCircle } from "lucide-react"; +import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; + +const formSchema = z.object({ + email: z.string().min(1, "Email is required").email({ message: "Invalid email address" }), + password: z.string().min(8, "Password requires at least 8 characters"), // Password has more criterias but we only let user know about length +}) + +export default function Login() { + const router = useRouter() + const [isLoading, setIsLoading] = useState(false); + const [error, setError] = useState(null); + + const form = useForm>({ + resolver: zodResolver(formSchema), + defaultValues: { + email: "", + password: "", + }, + }); + + async function onSubmit(values: z.infer) { + // Placeholder for auth to user service + try { + await form.trigger(); + if (!form.formState.isValid) { + return; + } + + setIsLoading(true); + + const response = await fetch(`${process.env.NEXT_PUBLIC_USER_API_AUTH_URL}/login`, { + method: "POST", + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(values), + }); + + if (response.status == 400) { + setError("Missing email or password."); + throw new Error("Missing email or password: " + response.statusText); + } else if (response.status == 401) { + setError("Incorrect email or password."); + throw new Error("Incorrect email or password: " + response.statusText); + } else if (response.status == 500) { + setError("Database or server error. Please try again."); + throw new Error("Database or server error: " + response.statusText); + } else if (!response.ok) { + setError("There was an error logging in. Please try again."); + throw new Error("Error logging in: " + response.statusText); + } + + const responseData = await response.json(); + console.log(responseData.data["accessToken"]); + router.push("/question-repo"); + } catch (error) { + console.error(error); + } finally { + setIsLoading(false); + } + } + + return ( +
+
+
+ + Sign in + +
+ {error && ( + + + Error + + {error} + + + )} +
+
+ + ( + + Email + + + + + + )} + /> + ( + + +
+ Password + + Forgot password? + +
+
+ + + + +
+ )} + /> + + + +
+ Don't have an account?{" "} + + Sign up + +
+
+
+
+ ) +} \ No newline at end of file diff --git a/frontend/app/page.tsx b/frontend/app/page.tsx index 110000cb96..e5262b0635 100644 --- a/frontend/app/page.tsx +++ b/frontend/app/page.tsx @@ -1,160 +1,27 @@ -"use client" - import { Button } from "@/components/ui/button"; -import { Input } from "@/components/ui/input"; import Link from "next/link"; -import { z } from "zod"; -import { useForm } from "react-hook-form"; -import { zodResolver } from "@hookform/resolvers/zod"; -import { - Form, - FormControl, - FormField, - FormItem, - FormLabel, - FormMessage, -} from "@/components/ui/form" -import { useRouter } from "next/navigation" -import { useState } from "react"; -import { AlertCircle, LoaderCircle } from "lucide-react"; -import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; - -const formSchema = z.object({ - email: z.string().min(1, "Email is required").email({ message: "Invalid email address" }), - password: z.string().min(8, "Password requires at least 8 characters"), // Password has more criterias but we only let user know about length -}) - -export default function Login() { - const router = useRouter() - const [isLoading, setIsLoading] = useState(false); - const [error, setError] = useState(null); - - const form = useForm>({ - resolver: zodResolver(formSchema), - defaultValues: { - email: "", - password: "", - }, - }); - - async function onSubmit(values: z.infer) { - // Placeholder for auth to user service - try { - await form.trigger(); - if (!form.formState.isValid) { - return; - } - - setIsLoading(true); - - const response = await fetch(`${process.env.NEXT_PUBLIC_USER_API_AUTH_URL}/login`, { - method: "POST", - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify(values), - }); - - if (response.status == 400) { - setError("Missing email or password."); - throw new Error("Missing email or password: " + response.statusText); - } else if (response.status == 401) { - setError("Incorrect email or password."); - throw new Error("Incorrect email or password: " + response.statusText); - } else if (response.status == 500) { - setError("Database or server error. Please try again."); - throw new Error("Database or server error: " + response.statusText); - } else if (!response.ok) { - setError("There was an error logging in. Please try again."); - throw new Error("Error logging in: " + response.statusText); - } - - const responseData = await response.json(); - console.log(responseData.data["accessToken"]); - router.push("/question-repo"); - } catch (error) { - console.error(error); - } finally { - setIsLoading(false); - } - } +export default function Landing() { return ( -
-
-
- - Sign in - -
- {error && ( - - - Error - - {error} - - - )} -
-
- - ( - - Email - - - - - - )} - /> - ( - - -
- Password - - Forgot password? - -
-
- - - - -
- )} - /> - - - -
- Don't have an account?{" "} - - Sign up - -
-
+
+

PeerPrep

+

Temporary landing page with all the links

+
+ + +
+
+ Forgot password (enter email for link) + Reset password (enter password to reset) + Profile page +
+
+ Questions (user facing) + Question Repo (CRUD)
) diff --git a/frontend/app/reset-password/page.tsx b/frontend/app/reset-password/page.tsx index 614e81daa6..c57478510f 100644 --- a/frontend/app/reset-password/page.tsx +++ b/frontend/app/reset-password/page.tsx @@ -15,7 +15,6 @@ import { FormLabel, FormMessage, } from "@/components/ui/form" -import { useRouter } from "next/navigation" import { useEffect, useState } from "react"; import { AlertCircle, LoaderCircle, TriangleAlert } from "lucide-react"; import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; @@ -124,7 +123,7 @@ export default function ResetPassword() { Password has been reset - Login here with your new password. + Login here with your new password. )} diff --git a/frontend/app/signup/page.tsx b/frontend/app/signup/page.tsx index 228e3728d3..2334c98a4e 100644 --- a/frontend/app/signup/page.tsx +++ b/frontend/app/signup/page.tsx @@ -238,7 +238,7 @@ export default function Signup() {
Already have an account?{" "} Sign in