From ece8f227c2dd14551da6b1be895425063b13db88 Mon Sep 17 00:00:00 2001 From: Callum Date: Sun, 8 Jan 2023 17:47:08 +0000 Subject: [PATCH] #224: Simplified error useEffect and renamed errors to errorMessages --- website/src/pages/auth/signin.tsx | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/website/src/pages/auth/signin.tsx b/website/src/pages/auth/signin.tsx index 14f81b4c..9a1d91a8 100644 --- a/website/src/pages/auth/signin.tsx +++ b/website/src/pages/auth/signin.tsx @@ -4,7 +4,7 @@ import Head from "next/head"; import Link from "next/link"; import { useRouter } from "next/router"; import { getCsrfToken, getProviders, signIn } from "next-auth/react"; -import React, { useRef, useEffect, useState } from "react"; +import React, { useEffect, useRef, useState } from "react"; import { FaBug, FaDiscord, FaEnvelope, FaGithub } from "react-icons/fa"; import { AuthLayout } from "src/components/AuthLayout"; import { Footer } from "src/components/Footer"; @@ -23,7 +23,7 @@ export type SignInErrorTypes = | "SessionRequired" | "default"; -const errors: Record = { +const errorMessages: Record = { Signin: "Try signing in with a different account.", OAuthSignin: "Try signing in with a different account.", OAuthCallback: "Try signing in with the same account you used originally.", @@ -45,13 +45,12 @@ function Signin({ csrfToken, providers }) { const [error, setError] = useState(""); useEffect(() => { - if (router?.query?.error) { - if (typeof router.query.error === "string") { - const errorType = errors[router.query.error]; - setError(errorType); + const err = router?.query?.error; + if (err) { + if (typeof err === "string") { + setError(errorMessages[err]); } else { - const errorType = errors[router.query.error[0]]; - setError(errorType); + setError(errorMessages[err[0]]); } } }, [router]);