tryHandleFirebaseAuthException<T> method
TurboResponse<T>
tryHandleFirebaseAuthException<T>({
- required FirebaseAuthException firebaseAuthException,
- required TLog log,
Handles Firebase Authentication exceptions and converts them to TurboResponse.
Takes a FirebaseAuthException and returns a TurboResponse with appropriate
error messages based on the exception code. Logs the error details using
the provided log instance.
Parameters:
firebaseAuthException- The Firebase Authentication exception to handlelog- Logger instance for error logging
Returns a TurboResponse with appropriate error details
Implementation
TurboResponse<T> tryHandleFirebaseAuthException<T>({
required FirebaseAuthException firebaseAuthException,
required TLog log,
}) {
log.error('Handling FirebaseAuthException: ${firebaseAuthException.code}');
log.error(
'Handling FirebaseAuthException: ${firebaseAuthException.message} ',
);
switch (firebaseAuthException.code) {
case TAuthErrors.invalidLoginCredentials:
return TurboResponse.fail(
error: firebaseAuthException,
title: 'Invalid credentials',
message: 'The credentials provided are invalid, please try again.',
);
case TAuthErrors.accountExistsWithDifferentCredentials:
return TurboResponse.fail(
error: firebaseAuthException,
title: 'Account already in use',
message: 'The account is already in use, please try again.',
);
case TAuthErrors.invalidCredential:
return TurboResponse.fail(
error: firebaseAuthException,
title: 'Invalid credential',
message:
'Something went wrong verifying the credential, please try again.',
);
case TAuthErrors.operationNotAllowed:
return TurboResponse.fail(
error: firebaseAuthException,
title: 'Operation not allowed',
message:
'The type of account corresponding to the credential is not enabled, please try again.',
);
case TAuthErrors.userDisabled:
return TurboResponse.fail(
error: firebaseAuthException,
title: 'Account disabled',
message:
'The account corresponding to the credential is disabled, please try again.',
);
case TAuthErrors.userNotFound:
return TurboResponse.fail(
error: firebaseAuthException,
title: 'Account not found',
message:
'The account corresponding to the credential was not found, please try again.',
);
case TAuthErrors.wrongPassword:
return TurboResponse.fail(
error: firebaseAuthException,
title: 'Wrong password',
message: 'The password is invalid, please try again.',
);
case TAuthErrors.invalidVerificationCode:
return TurboResponse.fail(
error: firebaseAuthException,
title: 'Invalid verification code',
message:
'The verification code of the credential is invalid, please try again.',
);
case TAuthErrors.invalidVerificationId:
return TurboResponse.fail(
error: firebaseAuthException,
title: 'Invalid verification id',
message:
'The verification id of the credential is invalid, please try again.',
);
case TAuthErrors.invalidEmail:
return TurboResponse.fail(
error: firebaseAuthException,
title: 'Invalid email',
message: 'The email address provided is invalid, please try again.',
);
case TAuthErrors.emailAlreadyInUse:
return TurboResponse.fail(
error: firebaseAuthException,
title: 'Email already in use',
message:
'The email used already exists, please use a different email or try to log in.',
);
case TAuthErrors.weakPassword:
return TurboResponse.fail(
error: firebaseAuthException,
title: 'Weak password',
message: 'The password provided is too weak, please try again.',
);
case TAuthErrors.invalidPhoneNumber:
return TurboResponse.fail(
error: firebaseAuthException,
title: 'Invalid Phone Number',
message:
'The phone number has an invalid format. Please input a valid phone number.',
);
case TAuthErrors.captchaCheckFailed:
return TurboResponse.fail(
error: firebaseAuthException,
title: 'Captcha Check Failed',
message:
'The reCAPTCHA response token was invalid or expired, or the request contained an invalid API key. Please try again.',
);
case TAuthErrors.quotaExceeded:
return TurboResponse.fail(
error: firebaseAuthException,
title: 'Quota Exceeded',
message:
'The quota of SMS verification messages has been exceeded. This is done to prevent abuse. Please try again later.',
);
case TAuthErrors.providerAlreadyLinked:
return TurboResponse.fail(
error: firebaseAuthException,
title: 'Provider Already Linked',
message:
'The provider account is already linked to another user account. Please use a different account or unlink the existing one.',
);
case TAuthErrors.credentialAlreadyInUse:
return TurboResponse.fail(
error: firebaseAuthException,
title: 'Credential Already In Use',
message:
'The account corresponding to the credential already exists among your users, or is already linked to a Firebase User. Please use a different credential.',
);
}
return TurboResponse.fail(
error: firebaseAuthException,
title: 'Unknown error',
message: 'An unknown error has occurred, please try again.',
);
}