fix signup button showing when it shouldnt
All checks were successful
Check / checks (push) Successful in 3m42s
All checks were successful
Check / checks (push) Successful in 3m42s
This commit is contained in:
parent
ad312d0091
commit
eca8fda6c2
|
@ -10,12 +10,19 @@ import classNames from "classnames"
|
||||||
import { Link, NavLink } from "react-router-dom"
|
import { Link, NavLink } from "react-router-dom"
|
||||||
|
|
||||||
import { useIsAuthenticated, useUser } from "../hooks/useAuth"
|
import { useIsAuthenticated, useUser } from "../hooks/useAuth"
|
||||||
|
import { useServerConfig } from "../hooks/useServerConfig"
|
||||||
|
|
||||||
import NavButton from "./NavButton"
|
import NavButton from "./NavButton"
|
||||||
|
|
||||||
export default function Navbar() {
|
export default function Navbar() {
|
||||||
const isAuthenticated = useIsAuthenticated()
|
const isAuthenticated = useIsAuthenticated()
|
||||||
const user = useUser()
|
const user = useUser()
|
||||||
|
const { disableRegistration, disableCredentialLogin } = useServerConfig()
|
||||||
|
|
||||||
|
const showRegisterButton = useMemo(
|
||||||
|
() => !disableRegistration && !disableCredentialLogin,
|
||||||
|
[disableRegistration, disableCredentialLogin]
|
||||||
|
)
|
||||||
|
|
||||||
const navigation = useMemo(() => {
|
const navigation = useMemo(() => {
|
||||||
const authed = [
|
const authed = [
|
||||||
|
@ -24,8 +31,10 @@ export default function Navbar() {
|
||||||
{ name: "Sessions", href: "ses" },
|
{ name: "Sessions", href: "ses" },
|
||||||
]
|
]
|
||||||
const unauthed = [{ name: "Register", href: "sgn" }]
|
const unauthed = [{ name: "Register", href: "sgn" }]
|
||||||
return isAuthenticated ? authed : unauthed
|
if (isAuthenticated) return authed
|
||||||
}, [isAuthenticated])
|
if (showRegisterButton) return unauthed
|
||||||
|
return []
|
||||||
|
}, [isAuthenticated, showRegisterButton])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Disclosure as="nav">
|
<Disclosure as="nav">
|
||||||
|
|
|
@ -104,7 +104,17 @@ const UserForm: FunctionComponent<{
|
||||||
}> = ({ action }) => {
|
}> = ({ action }) => {
|
||||||
const [params] = useSearchParams()
|
const [params] = useSearchParams()
|
||||||
const from = params.get("from") || "/"
|
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]
|
const opts = actionOptions[action]
|
||||||
|
|
||||||
|
@ -118,6 +128,11 @@ const UserForm: FunctionComponent<{
|
||||||
// to the page they were on before they logged in.
|
// to the page they were on before they logged in.
|
||||||
const altLink = from ? `${opts.altLink}?from=${from}` : opts.altLink
|
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 [password, setPassword] = useState("")
|
||||||
const onPasswordChange: ChangeEventHandler<HTMLInputElement> = (event) => {
|
const onPasswordChange: ChangeEventHandler<HTMLInputElement> = (event) => {
|
||||||
const password = event.target.value
|
const password = event.target.value
|
||||||
|
@ -133,7 +148,7 @@ const UserForm: FunctionComponent<{
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col mx-auto rounded-lg shadow-md p-8 max-w-md gap-y-6">
|
<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>
|
<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">
|
<Form method="post" replace className="flex flex-col gap-y-2">
|
||||||
{actionData && actionData.error ? (
|
{actionData && actionData.error ? (
|
||||||
<p className="text-red-500 text-center font-medium">
|
<p className="text-red-500 text-center font-medium">
|
||||||
|
@ -206,14 +221,14 @@ const UserForm: FunctionComponent<{
|
||||||
</Button>
|
</Button>
|
||||||
</Form>
|
</Form>
|
||||||
)}
|
)}
|
||||||
{!!serverConfig?.oidcIssuerUrl.length && (
|
{!!oidcIssuerUrl.length && (
|
||||||
<a href={`${import.meta.env.VITE_OIDC_URL}/redirect`}>
|
<a href={`${import.meta.env.VITE_OIDC_URL}/redirect`}>
|
||||||
<Button color="green" className="px-8 py-3 max-w-fit mx-auto">
|
<Button color="green" className="px-8 py-3 max-w-fit mx-auto">
|
||||||
{`${opts.buttonText} with ${serverConfig.oidcIssuerName}`}
|
{`${opts.buttonText} with ${oidcIssuerName}`}
|
||||||
</Button>
|
</Button>
|
||||||
</a>
|
</a>
|
||||||
)}
|
)}
|
||||||
{serverConfig.disableRegistration && action === "login" ? null : (
|
{!showRegisterButton && action === "login" ? null : (
|
||||||
<span className="text-slate-500 font-light text-center text-sm">
|
<span className="text-slate-500 font-light text-center text-sm">
|
||||||
{opts.altLabel + " "}
|
{opts.altLabel + " "}
|
||||||
<Link
|
<Link
|
||||||
|
|
Loading…
Reference in New Issue
Block a user