Skip to content

Commit 4924f76

Browse files
authored
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
1 parent f1f514d commit 4924f76

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

frontend/src/pages/index.tsx

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ import {
1010
} from "@mantine/core";
1111
import Link from "next/link";
1212
import { useRouter } from "next/router";
13-
import { useEffect } from "react";
13+
import { useEffect, useState } from "react";
1414
import { TbCheck } from "react-icons/tb";
1515
import { FormattedMessage } from "react-intl";
1616
import Logo from "../components/Logo";
1717
import Meta from "../components/Meta";
1818
import useUser from "../hooks/user.hook";
19+
import useConfig from "../hooks/config.hook";
1920

2021
const useStyles = createStyles((theme) => ({
2122
inner: {
@@ -73,15 +74,29 @@ export default function Home() {
7374
const { classes } = useStyles();
7475
const { refreshUser } = useUser();
7576
const router = useRouter();
77+
const config = useConfig();
78+
const [signupEnabled, setSignupEnabled] = useState(true);
7679

77-
// If the user is already logged in, redirect to the upload page
80+
// If user is already authenticated, redirect to the upload page
7881
useEffect(() => {
7982
refreshUser().then((user) => {
8083
if (user) {
8184
router.replace("/upload");
8285
}
8386
});
84-
}, []);
87+
88+
// If registration is disabled, get started button should redirect to the sign in page
89+
try {
90+
const allowRegistration = config.get("share.allowRegistration");
91+
setSignupEnabled(allowRegistration !== false);
92+
} catch (error) {
93+
setSignupEnabled(true);
94+
}
95+
}, [config]);
96+
97+
const getButtonHref = () => {
98+
return signupEnabled ? "/auth/signUp" : "/auth/signIn";
99+
};
85100

86101
return (
87102
<>
@@ -142,12 +157,14 @@ export default function Home() {
142157
<Group mt={30}>
143158
<Button
144159
component={Link}
145-
href="/auth/signUp"
160+
href={getButtonHref()}
146161
radius="xl"
147162
size="md"
148163
className={classes.control}
149164
>
150-
<FormattedMessage id="home.button.start" />
165+
<FormattedMessage
166+
id="home.button.start"
167+
/>
151168
</Button>
152169
<Button
153170
component={Link}
@@ -169,4 +186,4 @@ export default function Home() {
169186
</Container>
170187
</>
171188
);
172-
}
189+
}

0 commit comments

Comments
 (0)