1- import {
2- ConnectConditionalUIPasskeyDeleted ,
3- ConnectCustomError ,
4- ConnectExistingPasskeysNotAvailable ,
5- ConnectNoPasskeyAvailableError ,
6- ConnectUserNotFound ,
7- PasskeyChallengeCancelledError ,
8- PasskeyLoginSource ,
9- } from '@corbado/web-core' ;
1+ import { PasskeyChallengeCancelledError , PasskeyLoginSource } from '@corbado/web-core' ;
102import type { ConnectLoginFinishRsp } from '@corbado/web-core/dist/api/v2' ;
113import log from 'loglevel' ;
124import type { FC } from 'react' ;
@@ -16,12 +8,17 @@ import useLoginProcess from '../../hooks/useLoginProcess';
168import useShared from '../../hooks/useShared' ;
179import { Flags } from '../../types/flags' ;
1810import { LoginScreenType } from '../../types/screenTypes' ;
19- import type { PreAuthenticatorCustomErrorData } from '../../types/situations' ;
2011import { getLoginErrorMessage , LoginSituationCode } from '../../types/situations' ;
2112import { StatefulLoader } from '../../utils/statefulLoader' ;
2213import LoginInitLoaded from './base/LoginInitLoaded' ;
2314import LoginInitLoading from './base/LoginInitLoading' ;
2415
16+ export type CboApiFallbackOperationError = {
17+ initFallback : boolean ;
18+ identifierFallback : string ;
19+ message : string | null ;
20+ } ;
21+
2522export enum LoginInitState {
2623 SilentLoading ,
2724 Loading ,
@@ -42,8 +39,7 @@ export const connectLoginFinishToComplete = (v: ConnectLoginFinishRsp): string =
4239} ;
4340
4441const LoginInitScreen : FC < Props > = ( { showFallback = false } ) => {
45- const { config, navigateToScreen, setCurrentIdentifier, setFlags, flags, loadedMs, fallback, fallbackCustom } =
46- useLoginProcess ( ) ;
42+ const { config, navigateToScreen, setCurrentIdentifier, setFlags, flags, loadedMs, fallback } = useLoginProcess ( ) ;
4743 const { sharedConfig, getConnectService } = useShared ( ) ;
4844 const [ cuiBasedLoading , setCuiBasedLoading ] = useState ( false ) ;
4945 const [ identifierBasedLoading , setIdentifierBasedLoading ] = useState ( false ) ;
@@ -160,11 +156,6 @@ const LoginInitScreen: FC<Props> = ({ showFallback = false }) => {
160156 return handleSituation ( LoginSituationCode . ClientPasskeyConditionalOperationCancelled ) ;
161157 }
162158
163- // if a passkey has been deleted, CUI will fail => fallback with message
164- if ( res . val instanceof ConnectConditionalUIPasskeyDeleted ) {
165- return handleSituation ( LoginSituationCode . PasskeyNotAvailablePostConditionalAuthenticator ) ;
166- }
167-
168159 // cuiStarted === true indicates that user has passed the authenticator
169160 if ( cuiStarted ) {
170161 return handleSituation ( LoginSituationCode . CboApiNotAvailablePostConditionalAuthenticator ) ;
@@ -173,6 +164,16 @@ const LoginInitScreen: FC<Props> = ({ showFallback = false }) => {
173164 return handleSituation ( LoginSituationCode . CboApiNotAvailablePreConditionalAuthenticator ) ;
174165 }
175166
167+ if ( res . val . fallbackOperationError ) {
168+ const data : CboApiFallbackOperationError = {
169+ initFallback : res . val . fallbackOperationError . initFallback ,
170+ identifierFallback : res . val . fallbackOperationError . identifier ?? '' ,
171+ message : res . val . fallbackOperationError . error ?. message ?? null ,
172+ } ;
173+
174+ return handleSituation ( LoginSituationCode . CboApiFallbackOperationError , data ) ;
175+ }
176+
176177 try {
177178 await config . onComplete ( connectLoginFinishToComplete ( res . val ) ) ;
178179 } catch {
@@ -191,19 +192,6 @@ const LoginInitScreen: FC<Props> = ({ showFallback = false }) => {
191192
192193 const resStart = await getConnectService ( ) . loginStart ( identifier , PasskeyLoginSource . TextField , loadedMs ) ;
193194 if ( resStart . err ) {
194- if ( resStart . val instanceof ConnectUserNotFound ) {
195- return handleSituation ( LoginSituationCode . PreAuthenticatorUserNotFound ) ;
196- }
197- if ( resStart . val instanceof ConnectCustomError ) {
198- return handleSituation ( LoginSituationCode . PreAuthenticatorCustomError , resStart . val ) ;
199- }
200- if ( resStart . val instanceof ConnectExistingPasskeysNotAvailable ) {
201- return handleSituation ( LoginSituationCode . PreAuthenticatorExistingPasskeysNotAvailable ) ;
202- }
203- if ( resStart . val instanceof ConnectNoPasskeyAvailableError ) {
204- return handleSituation ( LoginSituationCode . PreAuthenticatorNoPasskeyAvailable ) ;
205- }
206-
207195 return handleSituation ( LoginSituationCode . CboApiNotAvailablePreAuthenticator ) ;
208196 }
209197
@@ -212,6 +200,16 @@ const LoginInitScreen: FC<Props> = ({ showFallback = false }) => {
212200 return ;
213201 }
214202
203+ if ( resStart . val . assertionOptions . length === 0 ) {
204+ const data : CboApiFallbackOperationError = {
205+ initFallback : resStart . val . fallbackOperationError . initFallback ,
206+ identifierFallback : resStart . val . fallbackOperationError . identifier ?? '' ,
207+ message : resStart . val . fallbackOperationError . error ?. message ?? null ,
208+ } ;
209+
210+ return handleSituation ( LoginSituationCode . CboApiFallbackOperationError , data ) ;
211+ }
212+
215213 const res = await getConnectService ( ) . loginContinue ( resStart . val ) ;
216214 if ( res . err ) {
217215 setIdentifierBasedLoading ( false ) ;
@@ -255,13 +253,10 @@ const LoginInitScreen: FC<Props> = ({ showFallback = false }) => {
255253 statefulLoader . current . finish ( ) ;
256254 break ;
257255 case LoginSituationCode . DeniedByPartialRollout :
258- case LoginSituationCode . PreAuthenticatorExistingPasskeysNotAvailable :
259- case LoginSituationCode . PreAuthenticatorNoPasskeyAvailable :
260256 automaticFallback ( identifier , message ) ;
261257
262258 statefulLoader . current . finish ( ) ;
263259 break ;
264- case LoginSituationCode . PasskeyNotAvailablePostConditionalAuthenticator :
265260 case LoginSituationCode . CboApiNotAvailablePostConditionalAuthenticator :
266261 case LoginSituationCode . CboApiNotAvailablePreConditionalAuthenticator :
267262 case LoginSituationCode . CtApiNotAvailablePostAuthenticator :
@@ -280,26 +275,22 @@ const LoginInitScreen: FC<Props> = ({ showFallback = false }) => {
280275 setIdentifierBasedLoading ( false ) ;
281276 break ;
282277 }
283- case LoginSituationCode . PreAuthenticatorUserNotFound :
284- setError ( message ?? '' ) ;
285- void getConnectService ( ) . recordEventLoginErrorUnexpected ( messageCode ) ;
286-
287- setIdentifierBasedLoading ( false ) ;
288- break ;
289278 case LoginSituationCode . ExplicitFallbackByUser :
290279 explicitFallback ( ) ;
291280
292281 void getConnectService ( ) . recordEventLoginExplicitAbort ( ) ;
293282 break ;
294- case LoginSituationCode . PreAuthenticatorCustomError : {
295- navigateToScreen ( LoginScreenType . Invisible ) ;
296- void getConnectService ( ) . recordEventLoginErrorUnexpected ( messageCode ) ;
297- if ( ! data ) {
298- return fallback ( identifier , null ) ;
283+ case LoginSituationCode . CboApiFallbackOperationError : {
284+ const typed = data as CboApiFallbackOperationError ;
285+
286+ if ( typed . initFallback ) {
287+ return automaticFallback ( typed . identifierFallback , typed . message ) ;
299288 }
300289
301- const typed = data as PreAuthenticatorCustomErrorData ;
302- fallbackCustom ( identifier , typed . code , typed . message ) ;
290+ setError ( typed . message ?? '' ) ;
291+ setCuiBasedLoading ( false ) ;
292+ setIdentifierBasedLoading ( false ) ;
293+ break ;
303294 }
304295 }
305296 } ;
0 commit comments