From eca8fda6c2e7d75a727a8b0154724d2868f27785 Mon Sep 17 00:00:00 2001 From: Gustavo Maronato Date: Sun, 10 Mar 2024 15:02:27 -0400 Subject: [PATCH] fix signup button showing when it shouldnt --- frontend/src/components/Navbar.tsx | 13 +++++++++++-- frontend/src/components/UserForm.tsx | 25 ++++++++++++++++++++----- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/frontend/src/components/Navbar.tsx b/frontend/src/components/Navbar.tsx index 784c032..f4cd7e0 100644 --- a/frontend/src/components/Navbar.tsx +++ b/frontend/src/components/Navbar.tsx @@ -10,12 +10,19 @@ import classNames from "classnames" import { Link, NavLink } from "react-router-dom" import { useIsAuthenticated, useUser } from "../hooks/useAuth" +import { useServerConfig } from "../hooks/useServerConfig" import NavButton from "./NavButton" export default function Navbar() { const isAuthenticated = useIsAuthenticated() const user = useUser() + const { disableRegistration, disableCredentialLogin } = useServerConfig() + + const showRegisterButton = useMemo( + () => !disableRegistration && !disableCredentialLogin, + [disableRegistration, disableCredentialLogin] + ) const navigation = useMemo(() => { const authed = [ @@ -24,8 +31,10 @@ export default function Navbar() { { name: "Sessions", href: "ses" }, ] const unauthed = [{ name: "Register", href: "sgn" }] - return isAuthenticated ? authed : unauthed - }, [isAuthenticated]) + if (isAuthenticated) return authed + if (showRegisterButton) return unauthed + return [] + }, [isAuthenticated, showRegisterButton]) return ( diff --git a/frontend/src/components/UserForm.tsx b/frontend/src/components/UserForm.tsx index 46b803c..667ec27 100644 --- a/frontend/src/components/UserForm.tsx +++ b/frontend/src/components/UserForm.tsx @@ -104,7 +104,17 @@ const UserForm: FunctionComponent<{ }> = ({ action }) => { const [params] = useSearchParams() const from = params.get("from") || "/" - const serverConfig = useServerConfig() + const { + disableRegistration, + disableCredentialLogin, + oidcIssuerUrl, + oidcIssuerName, + } = useServerConfig() + + const showRegisterButton = useMemo( + () => !disableRegistration && !disableCredentialLogin, + [disableRegistration, disableCredentialLogin] + ) const opts = actionOptions[action] @@ -118,6 +128,11 @@ const UserForm: FunctionComponent<{ // to the page they were on before they logged in. const altLink = from ? `${opts.altLink}?from=${from}` : opts.altLink + // Redirect user from signup if `showRegisterButton` is false + if (!showRegisterButton && action === "register") { + window.location.href = altLink + } + const [password, setPassword] = useState("") const onPasswordChange: ChangeEventHandler = (event) => { const password = event.target.value @@ -133,7 +148,7 @@ const UserForm: FunctionComponent<{ return (
{opts.title} - {serverConfig.disableCredentialLogin ? null : ( + {disableCredentialLogin ? null : (
{actionData && actionData.error ? (

@@ -206,14 +221,14 @@ const UserForm: FunctionComponent<{

)} - {!!serverConfig?.oidcIssuerUrl.length && ( + {!!oidcIssuerUrl.length && ( )} - {serverConfig.disableRegistration && action === "login" ? null : ( + {!showRegisterButton && action === "login" ? null : ( {opts.altLabel + " "}