@@ -10,12 +10,13 @@ import {
10
10
} from "@mantine/core" ;
11
11
import Link from "next/link" ;
12
12
import { useRouter } from "next/router" ;
13
- import { useEffect } from "react" ;
13
+ import { useEffect , useState } from "react" ;
14
14
import { TbCheck } from "react-icons/tb" ;
15
15
import { FormattedMessage } from "react-intl" ;
16
16
import Logo from "../components/Logo" ;
17
17
import Meta from "../components/Meta" ;
18
18
import useUser from "../hooks/user.hook" ;
19
+ import useConfig from "../hooks/config.hook" ;
19
20
20
21
const useStyles = createStyles ( ( theme ) => ( {
21
22
inner : {
@@ -73,15 +74,29 @@ export default function Home() {
73
74
const { classes } = useStyles ( ) ;
74
75
const { refreshUser } = useUser ( ) ;
75
76
const router = useRouter ( ) ;
77
+ const config = useConfig ( ) ;
78
+ const [ signupEnabled , setSignupEnabled ] = useState ( true ) ;
76
79
77
- // If the user is already logged in , redirect to the upload page
80
+ // If user is already authenticated , redirect to the upload page
78
81
useEffect ( ( ) => {
79
82
refreshUser ( ) . then ( ( user ) => {
80
83
if ( user ) {
81
84
router . replace ( "/upload" ) ;
82
85
}
83
86
} ) ;
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
+ } ;
85
100
86
101
return (
87
102
< >
@@ -142,12 +157,14 @@ export default function Home() {
142
157
< Group mt = { 30 } >
143
158
< Button
144
159
component = { Link }
145
- href = "/auth/signUp"
160
+ href = { getButtonHref ( ) }
146
161
radius = "xl"
147
162
size = "md"
148
163
className = { classes . control }
149
164
>
150
- < FormattedMessage id = "home.button.start" />
165
+ < FormattedMessage
166
+ id = "home.button.start"
167
+ />
151
168
</ Button >
152
169
< Button
153
170
component = { Link }
@@ -169,4 +186,4 @@ export default function Home() {
169
186
</ Container >
170
187
</ >
171
188
) ;
172
- }
189
+ }
0 commit comments