@@ -37,14 +37,14 @@ export default function LoginPage({
3737 const router = useRouter ( )
3838 const searchParams = useSearchParams ( )
3939 const [ isLoading , setIsLoading ] = useState ( false )
40- const [ , setMounted ] = useState ( false )
40+ const [ mounted , setMounted ] = useState ( false )
4141 const { addNotification } = useNotificationStore ( )
4242 const [ showPassword , setShowPassword ] = useState ( false )
4343 const [ password , setPassword ] = useState ( '' )
4444
45- // Extract callbackUrl from the URL for both form and OAuth providers
46- const callbackUrl = searchParams ?. get ( 'callbackUrl' ) || ' /w'
47- const isInviteFlow = searchParams ?. get ( 'invite_flow' ) === 'true'
45+ // Initialize state for URL parameters
46+ const [ callbackUrl , setCallbackUrl ] = useState ( ' /w')
47+ const [ isInviteFlow , setIsInviteFlow ] = useState ( false )
4848
4949 // Forgot password states
5050 const [ forgotPasswordOpen , setForgotPasswordOpen ] = useState ( false )
@@ -55,9 +55,21 @@ export default function LoginPage({
5555 message : string
5656 } > ( { type : null , message : '' } )
5757
58+ // Extract URL parameters after component mounts to avoid SSR issues
5859 useEffect ( ( ) => {
5960 setMounted ( true )
60- } , [ ] )
61+
62+ // Only access search params on the client side
63+ if ( searchParams ) {
64+ const callback = searchParams . get ( 'callbackUrl' )
65+ if ( callback ) {
66+ setCallbackUrl ( callback )
67+ }
68+
69+ const inviteFlow = searchParams . get ( 'invite_flow' ) === 'true'
70+ setIsInviteFlow ( inviteFlow )
71+ }
72+ } , [ searchParams ] )
6173
6274 async function onSubmit ( e : React . FormEvent < HTMLFormElement > ) {
6375 e . preventDefault ( )
@@ -228,12 +240,14 @@ export default function LoginPage({
228240 </ CardHeader >
229241 < CardContent >
230242 < div className = "grid gap-6" >
231- < SocialLoginButtons
232- githubAvailable = { githubAvailable }
233- googleAvailable = { googleAvailable }
234- callbackURL = { callbackUrl }
235- isProduction = { isProduction }
236- />
243+ { mounted && (
244+ < SocialLoginButtons
245+ githubAvailable = { githubAvailable }
246+ googleAvailable = { googleAvailable }
247+ callbackURL = { callbackUrl }
248+ isProduction = { isProduction }
249+ />
250+ ) }
237251 < div className = "relative" >
238252 < div className = "absolute inset-0 flex items-center" >
239253 < span className = "w-full border-t" />
@@ -300,7 +314,7 @@ export default function LoginPage({
300314 < p className = "text-sm text-gray-500 text-center w-full" >
301315 Don't have an account?{ ' ' }
302316 < Link
303- href = { `/signup ${ searchParams ? `?${ searchParams . toString ( ) } ` : '' } ` }
317+ href = { mounted && searchParams ? `/signup ?${ searchParams . toString ( ) } ` : '/signup' }
304318 className = "text-primary hover:underline"
305319 >
306320 Sign up
0 commit comments