diff --git a/public/blue-stock-photo.png b/public/blue-stock-photo.png new file mode 100644 index 00000000..4ac786da Binary files /dev/null and b/public/blue-stock-photo.png differ diff --git a/public/purple-stock-photo.png b/public/purple-stock-photo.png new file mode 100644 index 00000000..2ee82471 Binary files /dev/null and b/public/purple-stock-photo.png differ diff --git a/src/pages/login.tsx b/src/pages/login.tsx index d03ffe4a..09fee825 100644 --- a/src/pages/login.tsx +++ b/src/pages/login.tsx @@ -1,44 +1,45 @@ /* eslint-disable @next/next/no-img-element */ -import {User} from "@/interfaces/user"; -import {toast, ToastContainer} from "react-toastify"; +import { User } from "@/interfaces/user"; +import { toast, ToastContainer } from "react-toastify"; import axios from "axios"; -import {FormEvent, useEffect, useState} from "react"; +import { FormEvent, useEffect, useMemo, useState } from "react"; import Head from "next/head"; import useUser from "@/hooks/useUser"; -import {Divider} from "primereact/divider"; +import { Divider } from "primereact/divider"; import Button from "@/components/Low/Button"; -import {BsArrowRepeat, BsCheck} from "react-icons/bs"; +import { BsArrowRepeat, BsCheck } from "react-icons/bs"; import Link from "next/link"; import Input from "@/components/Low/Input"; import clsx from "clsx"; -import {useRouter} from "next/router"; +import { useRouter } from "next/router"; import EmailVerification from "./(auth)/EmailVerification"; -import {withIronSessionSsr} from "iron-session/next"; -import {sessionOptions} from "@/lib/session"; +import { withIronSessionSsr } from "iron-session/next"; +import { sessionOptions } from "@/lib/session"; import { requestUser } from "@/utils/api"; import { redirect } from "@/utils"; const EMAIL_REGEX = new RegExp(/^[a-zA-Z0-9]+(?:\.[a-zA-Z0-9]+)*@[a-zA-Z0-9]+(?:\.[a-zA-Z0-9]+)*$/g); -export const getServerSideProps = withIronSessionSsr(async ({req, res, query}) => { +export const getServerSideProps = withIronSessionSsr(async ({ req, res, query }) => { const destination = !query.destination ? "/" : Buffer.from(query.destination as string, 'base64').toString() const user = await requestUser(req, res) if (user) return redirect(destination) return { - props: {user: null, destination}, + props: { user: null, destination }, }; }, sessionOptions); -export default function Login({ destination }: { destination: string }) { +export default function Login({ destination = "/" }: { destination?: string }) { const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [rememberPassword, setRememberPassword] = useState(false); const [isLoading, setIsLoading] = useState(false); const router = useRouter(); + const isOfficialExamLogin = useMemo(() => destination.startsWith("/official-exam"), [destination]) - const {user, mutateUser} = useUser({ + const { user, mutateUser } = useUser({ redirectTo: destination, redirectIfFound: true, }); @@ -56,10 +57,10 @@ export default function Login({ destination }: { destination: string }) { } axios - .post<{ok: boolean}>("/api/reset", {email}) + .post<{ ok: boolean }>("/api/reset", { email }) .then((response) => { if (response.data.ok) { - toast.success("You should receive an e-mail to reset your password!", {toastId: "forgot-success"}); + toast.success("You should receive an e-mail to reset your password!", { toastId: "forgot-success" }); return; } @@ -79,7 +80,7 @@ export default function Login({ destination }: { destination: string }) { setIsLoading(true); axios - .post("/api/login", {email, password}) + .post("/api/login", { email, password }) .then((response) => { toast.success("You have been logged in!", { toastId: "login-successful", @@ -92,7 +93,7 @@ export default function Login({ destination }: { destination: string }) { toastId: "wrong-credentials", }); } else { - toast.error("Something went wrong!", {toastId: "server-error"}); + toast.error("Something went wrong!", { toastId: "server-error" }); } setIsLoading(false); }) @@ -110,14 +111,25 @@ export default function Login({ destination }: { destination: string }) {
- {/*
*/} - People smiling looking at a tablet + {!isOfficialExamLogin && ( + People smiling looking at a tablet + )} + {isOfficialExamLogin && ( + People smiling looking at a tablet + )}
EnCoach's Logo -

Login to your account

-

with your registered Email Address

+ {!isOfficialExamLogin && ( + <> +

Login to your account

+

with your registered Email Address

+ + )} + {isOfficialExamLogin && ( +

Welcome to the Official Exams Portal

+ )}
{!user && (