22
33import { useEffect , useState } from 'react'
44import Link from 'next/link'
5- import { useRouter } from 'next/navigation'
5+ import { useRouter , useSearchParams } from 'next/navigation'
66import { Eye , EyeOff } from 'lucide-react'
77import { Button } from '@/components/ui/button'
88import {
@@ -35,12 +35,17 @@ export default function LoginPage({
3535 isProduction : boolean
3636} ) {
3737 const router = useRouter ( )
38+ const searchParams = useSearchParams ( )
3839 const [ isLoading , setIsLoading ] = useState ( false )
3940 const [ , setMounted ] = useState ( false )
4041 const { addNotification } = useNotificationStore ( )
4142 const [ showPassword , setShowPassword ] = useState ( false )
4243 const [ password , setPassword ] = useState ( '' )
4344
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'
48+
4449 // Forgot password states
4550 const [ forgotPasswordOpen , setForgotPasswordOpen ] = useState ( false )
4651 const [ forgotPasswordEmail , setForgotPasswordEmail ] = useState ( '' )
@@ -62,11 +67,12 @@ export default function LoginPage({
6267 const email = formData . get ( 'email' ) as string
6368
6469 try {
70+ // Use the extracted callbackUrl instead of hardcoded value
6571 const result = await client . signIn . email (
6672 {
6773 email,
6874 password,
69- callbackURL : '/w' ,
75+ callbackURL : callbackUrl ,
7076 } ,
7177 {
7278 onError : ( ctx ) => {
@@ -214,14 +220,18 @@ export default function LoginPage({
214220 < Card className = "w-full" >
215221 < CardHeader >
216222 < CardTitle > Welcome back</ CardTitle >
217- < CardDescription > Enter your credentials to access your account</ CardDescription >
223+ < CardDescription >
224+ { isInviteFlow
225+ ? 'Sign in to continue to the invitation'
226+ : 'Enter your credentials to access your account' }
227+ </ CardDescription >
218228 </ CardHeader >
219229 < CardContent >
220230 < div className = "grid gap-6" >
221231 < SocialLoginButtons
222232 githubAvailable = { githubAvailable }
223233 googleAvailable = { googleAvailable }
224- callbackURL = "/w"
234+ callbackURL = { callbackUrl }
225235 isProduction = { isProduction }
226236 />
227237 < div className = "relative" >
@@ -289,7 +299,10 @@ export default function LoginPage({
289299 < CardFooter >
290300 < p className = "text-sm text-gray-500 text-center w-full" >
291301 Don't have an account?{ ' ' }
292- < Link href = "/signup" className = "text-primary hover:underline" >
302+ < Link
303+ href = { `/signup${ searchParams ? `?${ searchParams . toString ( ) } ` : '' } ` }
304+ className = "text-primary hover:underline"
305+ >
293306 Sign up
294307 </ Link >
295308 </ p >
0 commit comments