fix signup button showing when it shouldnt
All checks were successful
Check / checks (push) Successful in 3m42s

This commit is contained in:
Gustavo Maronato 2024-03-10 15:02:27 -04:00
parent ad312d0091
commit eca8fda6c2
Signed by: maronato
SSH Key Fingerprint: SHA256:2Gw7kwMz/As+2UkR1qQ/qYYhn+WNh3FGv6ozhoRrLcs
2 changed files with 31 additions and 7 deletions

View File

@ -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 (
<Disclosure as="nav">

View File

@ -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<HTMLInputElement> = (event) => {
const password = event.target.value
@ -133,7 +148,7 @@ const UserForm: FunctionComponent<{
return (
<div className="flex flex-col mx-auto rounded-lg shadow-md p-8 max-w-md gap-y-6">
<span className="text-3xl font-bold text-center mb-4">{opts.title}</span>
{serverConfig.disableCredentialLogin ? null : (
{disableCredentialLogin ? null : (
<Form method="post" replace className="flex flex-col gap-y-2">
{actionData && actionData.error ? (
<p className="text-red-500 text-center font-medium">
@ -206,14 +221,14 @@ const UserForm: FunctionComponent<{
</Button>
</Form>
)}
{!!serverConfig?.oidcIssuerUrl.length && (
{!!oidcIssuerUrl.length && (
<a href={`${import.meta.env.VITE_OIDC_URL}/redirect`}>
<Button color="green" className="px-8 py-3 max-w-fit mx-auto">
{`${opts.buttonText} with ${serverConfig.oidcIssuerName}`}
{`${opts.buttonText} with ${oidcIssuerName}`}
</Button>
</a>
)}
{serverConfig.disableRegistration && action === "login" ? null : (
{!showRegisterButton && action === "login" ? null : (
<span className="text-slate-500 font-light text-center text-sm">
{opts.altLabel + " "}
<Link