@@ -74,12 +74,12 @@ const validatePassword = (passwordValue: string): string[] => {
7474
7575 if ( ! PASSWORD_VALIDATIONS . required . test ( passwordValue ) ) {
7676 errors . push ( PASSWORD_VALIDATIONS . required . message )
77- return errors // Return early for required field
77+ return errors
7878 }
7979
8080 if ( ! PASSWORD_VALIDATIONS . notEmpty . test ( passwordValue ) ) {
8181 errors . push ( PASSWORD_VALIDATIONS . notEmpty . message )
82- return errors // Return early for empty field
82+ return errors
8383 }
8484
8585 return errors
@@ -104,11 +104,9 @@ export default function LoginPage({
104104 const [ showValidationError , setShowValidationError ] = useState ( false )
105105 const [ buttonClass , setButtonClass ] = useState ( 'auth-button-gradient' )
106106
107- // Initialize state for URL parameters
108107 const [ callbackUrl , setCallbackUrl ] = useState ( '/workspace' )
109108 const [ isInviteFlow , setIsInviteFlow ] = useState ( false )
110109
111- // Forgot password states
112110 const [ forgotPasswordOpen , setForgotPasswordOpen ] = useState ( false )
113111 const [ forgotPasswordEmail , setForgotPasswordEmail ] = useState ( '' )
114112 const [ isSubmittingReset , setIsSubmittingReset ] = useState ( false )
@@ -117,38 +115,31 @@ export default function LoginPage({
117115 message : string
118116 } > ( { type : null , message : '' } )
119117
120- // Email validation state
121118 const [ email , setEmail ] = useState ( '' )
122119 const [ emailErrors , setEmailErrors ] = useState < string [ ] > ( [ ] )
123120 const [ showEmailValidationError , setShowEmailValidationError ] = useState ( false )
124121
125- // Extract URL parameters after component mounts to avoid SSR issues
126122 useEffect ( ( ) => {
127123 setMounted ( true )
128124
129- // Only access search params on the client side
130125 if ( searchParams ) {
131126 const callback = searchParams . get ( 'callbackUrl' )
132127 if ( callback ) {
133- // Validate the callbackUrl before setting it
134128 if ( validateCallbackUrl ( callback ) ) {
135129 setCallbackUrl ( callback )
136130 } else {
137131 logger . warn ( 'Invalid callback URL detected and blocked:' , { url : callback } )
138- // Keep the default safe value ('/workspace')
139132 }
140133 }
141134
142135 const inviteFlow = searchParams . get ( 'invite_flow' ) === 'true'
143136 setIsInviteFlow ( inviteFlow )
144137 }
145138
146- // Check if CSS variable has been customized
147139 const checkCustomBrand = ( ) => {
148140 const computedStyle = getComputedStyle ( document . documentElement )
149141 const brandAccent = computedStyle . getPropertyValue ( '--brand-accent-hex' ) . trim ( )
150142
151- // Check if the CSS variable exists and is different from the default
152143 if ( brandAccent && brandAccent !== '#6f3dfa' ) {
153144 setButtonClass ( 'auth-button-custom' )
154145 } else {
@@ -158,7 +149,6 @@ export default function LoginPage({
158149
159150 checkCustomBrand ( )
160151
161- // Also check on window resize or theme changes
162152 window . addEventListener ( 'resize' , checkCustomBrand )
163153 const observer = new MutationObserver ( checkCustomBrand )
164154 observer . observe ( document . documentElement , {
@@ -189,7 +179,6 @@ export default function LoginPage({
189179 const newEmail = e . target . value
190180 setEmail ( newEmail )
191181
192- // Silently validate but don't show errors until submit
193182 const errors = validateEmailField ( newEmail )
194183 setEmailErrors ( errors )
195184 setShowEmailValidationError ( false )
@@ -199,7 +188,6 @@ export default function LoginPage({
199188 const newPassword = e . target . value
200189 setPassword ( newPassword )
201190
202- // Silently validate but don't show errors until submit
203191 const errors = validatePassword ( newPassword )
204192 setPasswordErrors ( errors )
205193 setShowValidationError ( false )
@@ -210,26 +198,23 @@ export default function LoginPage({
210198 setIsLoading ( true )
211199
212200 const formData = new FormData ( e . currentTarget )
213- const email = formData . get ( 'email' ) as string
201+ const emailRaw = formData . get ( 'email' ) as string
202+ const email = emailRaw . trim ( ) . toLowerCase ( )
214203
215- // Validate email on submit
216204 const emailValidationErrors = validateEmailField ( email )
217205 setEmailErrors ( emailValidationErrors )
218206 setShowEmailValidationError ( emailValidationErrors . length > 0 )
219207
220- // Validate password on submit
221208 const passwordValidationErrors = validatePassword ( password )
222209 setPasswordErrors ( passwordValidationErrors )
223210 setShowValidationError ( passwordValidationErrors . length > 0 )
224211
225- // If there are validation errors, stop submission
226212 if ( emailValidationErrors . length > 0 || passwordValidationErrors . length > 0 ) {
227213 setIsLoading ( false )
228214 return
229215 }
230216
231217 try {
232- // Final validation before submission
233218 const safeCallbackUrl = validateCallbackUrl ( callbackUrl ) ? callbackUrl : '/workspace'
234219
235220 const result = await client . signIn . email (
@@ -291,33 +276,13 @@ export default function LoginPage({
291276 setIsLoading ( false )
292277 return
293278 }
294-
295- // Mark that the user has previously logged in
296- if ( typeof window !== 'undefined' ) {
297- localStorage . setItem ( 'has_logged_in_before' , 'true' )
298- document . cookie = 'has_logged_in_before=true; path=/; max-age=31536000; SameSite=Lax' // 1 year expiry
299- }
300279 } catch ( err : any ) {
301- // Handle only the special verification case that requires a redirect
302280 if ( err . message ?. includes ( 'not verified' ) || err . code ?. includes ( 'EMAIL_NOT_VERIFIED' ) ) {
303- try {
304- await client . emailOtp . sendVerificationOtp ( {
305- email,
306- type : 'email-verification' ,
307- } )
308-
309- if ( typeof window !== 'undefined' ) {
310- sessionStorage . setItem ( 'verificationEmail' , email )
311- }
312-
313- router . push ( '/verify' )
314- return
315- } catch ( _verifyErr ) {
316- setPasswordErrors ( [ 'Failed to send verification code. Please try again later.' ] )
317- setShowValidationError ( true )
318- setIsLoading ( false )
319- return
281+ if ( typeof window !== 'undefined' ) {
282+ sessionStorage . setItem ( 'verificationEmail' , email )
320283 }
284+ router . push ( '/verify' )
285+ return
321286 }
322287
323288 console . error ( 'Uncaught login error:' , err )
0 commit comments