/* eslint-disable @next/next/no-img-element */ import {toast, ToastContainer} from "react-toastify"; import axios from "axios"; import {FormEvent, useEffect, useState} from "react"; import Head from "next/head"; import useUser from "@/hooks/useUser"; import {Divider} from "primereact/divider"; import Button from "@/components/Low/Button"; import {BsArrowRepeat} from "react-icons/bs"; import Link from "next/link"; import Input from "@/components/Low/Input"; import {useRouter} from "next/router"; export function getServerSideProps({ query, res, }: { query: { oobCode: string; mode: string; continueUrl?: string; }; res: any; }) { if (!query || !query.oobCode || !query.mode) { return { redirect: { destination: "/login", permanent: false, } }; } return { props: { code: query.oobCode, mode: query.mode, ...(query.continueUrl ? {continueUrl: query.continueUrl} : {}), }, }; } export default function Reset({code, mode, continueUrl}: {code: string; mode: string; continueUrl?: string}) { const [password, setPassword] = useState(""); const [isLoading, setIsLoading] = useState(false); const router = useRouter(); useUser({ redirectTo: "/", redirectIfFound: true, }); useEffect(() => { if (mode === "signIn") { axios .post<{ok: boolean}>("/api/reset/verify", { email: continueUrl?.replace("https://platform.encoach.com/", "").replace("https://staging.encoach.com/", ""), }) .then((response) => { if (response.data.ok) { toast.success("Your account has been verified!", { toastId: "verify-successful", }); setTimeout(() => { router.push("/"); }, 1000); return; } toast.error("Something went wrong! Please make sure to click the link in your e-mail again and input the correct e-mail!", { toastId: "verify-error", }); }) .catch(() => { toast.error("Something went wrong! Please make sure to click the link in your e-mail again and input the correct e-mail!", { toastId: "verify-error", }); setIsLoading(false); }); } }); const login = (e: FormEvent) => { e.preventDefault(); setIsLoading(true); axios .post<{ok: boolean}>("/api/reset/confirm", {code, password}) .then((response) => { if (response.data.ok) { toast.success("Your password has been reset!", { toastId: "reset-successful", }); setTimeout(() => { router.push("/login"); }, 1000); return; } toast.error("Something went wrong! Please make sure to click the link in your e-mail again!", {toastId: "reset-error"}); }) .catch(() => { toast.error("Something went wrong! Please make sure to click the link in your e-mail again!", {toastId: "reset-error"}); }) .finally(() => setIsLoading(false)); }; return ( <> Reset | EnCoach
People smiling looking at a tablet
{mode === "resetPassword" && (
EnCoach's Logo

Reset your password

to your registered Email Address

setPassword(e)} placeholder="Password" />
Don't have an account?{" "} Sign up
)} {mode === "signIn" && (
EnCoach's Logo

Confirm your account

to your registered Email Address

Your e-mail is currently being verified, please wait a second.

Once it has been verified, you will be redirected to the home page.
)}
); }