From 4924f763947c9a6b79ba0d85887f104ed9545c78 Mon Sep 17 00:00:00 2001 From: Matt Burns <1515005+m6urns@users.noreply.github.com> Date: Tue, 20 Aug 2024 14:53:46 -0600 Subject: [PATCH] fix: get started button on home page not working when sign-up is disabled * Redirect to sign in page if sign ups are disabled on an instance * Add a comment back, add a comment in * Remove english default Get Started text --- frontend/src/pages/index.tsx | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/frontend/src/pages/index.tsx b/frontend/src/pages/index.tsx index d2635ef0..282224df 100644 --- a/frontend/src/pages/index.tsx +++ b/frontend/src/pages/index.tsx @@ -10,12 +10,13 @@ import { } from "@mantine/core"; import Link from "next/link"; import { useRouter } from "next/router"; -import { useEffect } from "react"; +import { useEffect, useState } from "react"; import { TbCheck } from "react-icons/tb"; import { FormattedMessage } from "react-intl"; import Logo from "../components/Logo"; import Meta from "../components/Meta"; import useUser from "../hooks/user.hook"; +import useConfig from "../hooks/config.hook"; const useStyles = createStyles((theme) => ({ inner: { @@ -73,15 +74,29 @@ export default function Home() { const { classes } = useStyles(); const { refreshUser } = useUser(); const router = useRouter(); + const config = useConfig(); + const [signupEnabled, setSignupEnabled] = useState(true); - // If the user is already logged in, redirect to the upload page + // If user is already authenticated, redirect to the upload page useEffect(() => { refreshUser().then((user) => { if (user) { router.replace("/upload"); } }); - }, []); + + // If registration is disabled, get started button should redirect to the sign in page + try { + const allowRegistration = config.get("share.allowRegistration"); + setSignupEnabled(allowRegistration !== false); + } catch (error) { + setSignupEnabled(true); + } + }, [config]); + + const getButtonHref = () => { + return signupEnabled ? "/auth/signUp" : "/auth/signIn"; + }; return ( <> @@ -142,12 +157,14 @@ export default function Home() {