@@ -9,6 +9,7 @@ import { isMobileDevice, getDeepLinkUrl } from '@lib/utils/mobile-detection';
99export function LoginMain ( ) : JSX . Element {
1010 const { signInWithCustomToken } = useAuth ( ) ;
1111 const [ qr , setQr ] = useState < string > ( ) ;
12+ const [ errorMessage , setErrorMessage ] = useState < string | null > ( null ) ;
1213
1314 function watchEventStream ( id : string ) : void {
1415 const sseUrl = new URL (
@@ -19,13 +20,37 @@ export function LoginMain(): JSX.Element {
1920
2021 eventSource . onopen = ( ) : void => {
2122 console . log ( 'Successfully connected.' ) ;
23+ setErrorMessage ( null ) ;
2224 } ;
2325
2426 eventSource . onmessage = async ( e ) : Promise < void > => {
25- const data = JSON . parse ( e . data as string ) as { token : string } ;
26- const { token } = data ;
27- console . log ( token ) ;
28- await signInWithCustomToken ( token ) ;
27+ const data = JSON . parse ( e . data as string ) as {
28+ token ?: string ;
29+ error ?: boolean ;
30+ message ?: string ;
31+ type ?: string ;
32+ } ;
33+
34+ // Check for error messages (version mismatch)
35+ if ( data . error && data . type === 'version_mismatch' ) {
36+ setErrorMessage (
37+ data . message ||
38+ 'Your eID Wallet app version is outdated. Please update to continue.'
39+ ) ;
40+ eventSource . close ( ) ;
41+ return ;
42+ }
43+
44+ // Handle successful authentication
45+ if ( data . token ) {
46+ console . log ( data . token ) ;
47+ await signInWithCustomToken ( data . token ) ;
48+ }
49+ } ;
50+
51+ eventSource . onerror = ( ) : void => {
52+ console . error ( 'SSE connection error' ) ;
53+ eventSource . close ( ) ;
2954 } ;
3055 }
3156 const getOfferData = async ( ) : Promise < void > => {
@@ -89,6 +114,14 @@ export function LoginMain(): JSX.Element {
89114 Join Blabsy today.
90115 </ h2 >
91116 < div >
117+ { errorMessage && (
118+ < div className = 'mb-4 p-4 bg-red-100 border border-red-400 text-red-700 rounded-lg' >
119+ < p className = 'font-semibold' >
120+ Authentication Error
121+ </ p >
122+ < p className = 'text-sm' > { errorMessage } </ p >
123+ </ div >
124+ ) }
92125 { isMobileDevice ( ) ? (
93126 < div className = 'flex flex-col gap-4 items-center' >
94127 < div className = 'text-xs text-gray-500 text-center max-w-xs' >
0 commit comments