@@ -32,32 +32,22 @@ export default function Login() {
3232 } , [ trackEvent ] )
3333 ) ;
3434
35+ // Handle successful authenticated state → navigate to app
3536 useEffect ( ( ) => {
3637 if ( status === 'signedIn' && isAuthenticated ) {
37- logger . info ( {
38- message : 'Login successful, redirecting to home' ,
39- } ) ;
40-
41- // Track successful login
42- trackEvent ( 'login_success' , {
43- timestamp : new Date ( ) . toISOString ( ) ,
44- } ) ;
45-
38+ logger . info ( { message : 'Login successful, redirecting to home' } ) ;
39+ trackEvent ( 'login_success' , { timestamp : new Date ( ) . toISOString ( ) } ) ;
4640 router . push ( '/(app)' ) ;
4741 }
4842 } , [ status , isAuthenticated , router , trackEvent ] ) ;
4943
44+ // Show error modal on login failure
5045 useEffect ( ( ) => {
5146 if ( status === 'error' ) {
52- logger . error ( {
53- message : 'Login failed' ,
54- context : { error } ,
55- } ) ;
47+ logger . error ( { message : 'Login failed' , context : { error } } ) ;
5648
57- // Safe analytics: classify and truncate error before tracking
5849 try {
5950 const timestamp = new Date ( ) . toISOString ( ) ;
60- // Treat error as string and classify based on content
6151 const rawMessage = error ?? '' ;
6252 let errorCode = 'unknown_error' ;
6353 if ( rawMessage . includes ( 'TypeError' ) ) {
@@ -67,31 +57,27 @@ export default function Login() {
6757 } else if ( rawMessage . toLowerCase ( ) . includes ( 'auth' ) ) {
6858 errorCode = 'auth_error' ;
6959 }
70- // Truncate message to 100 chars
71- const message = rawMessage . slice ( 0 , 100 ) ;
7260 trackEvent ( 'login_failed' , {
7361 timestamp,
7462 errorCode,
7563 category : 'login_error' ,
76- message,
64+ message : rawMessage . slice ( 0 , 100 ) ,
7765 } ) ;
7866 } catch {
79- // Swallow analytics errors, log non-sensitive warning
8067 logger . warn ( { message : 'Failed to track login_failed event' } ) ;
8168 }
8269
8370 setIsErrorModalVisible ( true ) ;
8471 }
8572 } , [ status , error , trackEvent ] ) ;
8673
87- const onSubmit : LoginFormProps [ 'onSubmit' ] = async ( data ) => {
74+ const onLocalLoginSubmit : LoginFormProps [ 'onSubmit' ] = async ( data ) => {
8875 const usernameHash = data . username ? CryptoJS . HmacSHA256 ( data . username , Env . LOGGING_KEY || '' ) . toString ( ) : null ;
8976 logger . info ( {
9077 message : 'Starting Login (button press)' ,
9178 context : { hasUsername : Boolean ( data . username ) , usernameHash } ,
9279 } ) ;
9380
94- // Track login attempt
9581 try {
9682 trackEvent ( 'login_attempted' , {
9783 timestamp : new Date ( ) . toISOString ( ) ,
@@ -112,15 +98,11 @@ export default function Login() {
11298 return (
11399 < >
114100 < FocusAwareStatusBar />
115- < LoginForm onSubmit = { onSubmit } isLoading = { status === 'loading' } { ...( error ? { error } : { } ) } />
116101
117- < Modal
118- isOpen = { isErrorModalVisible }
119- onClose = { ( ) => {
120- setIsErrorModalVisible ( false ) ;
121- } }
122- size = "full"
123- >
102+ < LoginForm onSubmit = { onLocalLoginSubmit } isLoading = { status === 'loading' } onSsoPress = { ( ) => router . push ( '/login/sso' ) } { ...( error ? { error } : { } ) } />
103+
104+ { /* Error modal */ }
105+ < Modal isOpen = { isErrorModalVisible } onClose = { ( ) => setIsErrorModalVisible ( false ) } size = "full" >
124106 < ModalBackdrop />
125107 < ModalContent className = "m-4 w-full max-w-3xl rounded-2xl" >
126108 < ModalHeader >
0 commit comments