diff --git a/app/auth/sign-in/page.tsx b/app/auth/sign-in/page.tsx index 5fbd4e08..460b4720 100644 --- a/app/auth/sign-in/page.tsx +++ b/app/auth/sign-in/page.tsx @@ -6,6 +6,15 @@ import { useRouter } from "next/navigation"; import styles from "./signin-page.module.css"; import Image from "next/image"; import mascot from "../../nsc_mascot_green_cropped.png"; +import { + Container, + Paper, + Box, + TextField, + Button, + Typography, + Link as MuiLink, +} from "@mui/material"; const Signin = () => { const [error, setError] = useState(""); @@ -13,7 +22,7 @@ const Signin = () => { email: "", password: "", }); - + const router = useRouter(); const { email, password } = userInfo; @@ -37,62 +46,109 @@ const Signin = () => { }), }); if (!res.ok) { - alert("Invalid email or password"); // error message for now - throw new Error(await res.text()); - } - const { token } = await res.json(); - localStorage.setItem("token", token); // store token in local storage - const userRole = JSON.parse(atob(token.split(".")[1])).role; // decode token to get user role - // Redirect to user page - if (userRole === "admin") { - router.push("/admin-page"); // redirect to admin-page which is not created yet - } else if (userRole === "creator") { - router.push("/creator-page"); // redirect to creator-page + setError("Invalid email or password"); } else { - router.push("/profile"); // TODO: change profile to user-page + const { token } = await res.json(); + const userRole = JSON.parse(atob(token.split(".")[1])).role; // decode token to get user role + // Redirect to user page + if (userRole === "admin") { + router.push("/admin-page"); // redirect to admin-page which is not created yet + } else if (userRole === "creator") { + router.push("/creator-page"); // redirect to creator-page + } else { + router.push("/profile"); // TODO: change profile to user-page + } } }; return ( -