Skip to content

Commit 3c64622

Browse files
committed
fix(deployment): login
1 parent 6ef482e commit 3c64622

File tree

5 files changed

+45
-13
lines changed

5 files changed

+45
-13
lines changed

apps/sim/app/(auth)/components/social-login-buttons.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client'
22

3-
import { useState } from 'react'
3+
import { useEffect, useState } from 'react'
44
import { GithubIcon, GoogleIcon } from '@/components/icons'
55
import { Button } from '@/components/ui/button'
66
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'
@@ -23,6 +23,15 @@ export function SocialLoginButtons({
2323
const [isGithubLoading, setIsGithubLoading] = useState(false)
2424
const [isGoogleLoading, setIsGoogleLoading] = useState(false)
2525
const { addNotification } = useNotificationStore()
26+
const [mounted, setMounted] = useState(false)
27+
28+
// Set mounted state to true on client-side
29+
useEffect(() => {
30+
setMounted(true)
31+
}, [])
32+
33+
// Only render on the client side to avoid hydration errors
34+
if (!mounted) return null
2635

2736
async function signInWithGithub() {
2837
if (!githubAvailable) return

apps/sim/app/(auth)/login/login-form.tsx

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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

apps/sim/app/(auth)/login/page.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { getOAuthProviderStatus } from '../components/oauth-provider-checker'
22
import LoginForm from './login-form'
33

4+
// Force dynamic rendering to avoid prerender errors with search params
5+
export const dynamic = 'force-dynamic'
6+
47
export default async function LoginPage() {
58
const { githubAvailable, googleAvailable, isProduction } = await getOAuthProviderStatus()
69

apps/sim/app/(auth)/signup/page.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { getOAuthProviderStatus } from '../components/oauth-provider-checker'
22
import SignupForm from './signup-form'
33

4+
// Force dynamic rendering to avoid prerender errors with search params
5+
export const dynamic = 'force-dynamic'
6+
47
export default async function SignupPage() {
58
const { githubAvailable, googleAvailable, isProduction } = await getOAuthProviderStatus()
69

apps/sim/app/(auth)/verify/page.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { isProd } from '@/lib/environment'
22
import { getBaseUrl } from '@/lib/urls/utils'
33
import { VerifyContent } from './verify-content'
44

5+
// Force dynamic rendering to avoid prerender errors with search params
6+
export const dynamic = 'force-dynamic'
7+
58
export default function VerifyPage() {
69
const baseUrl = getBaseUrl()
710

0 commit comments

Comments
 (0)