Last active
July 26, 2018 01:04
-
-
Save SamMatthewsIsACommonName/ed4a11b28095dc22cbf82cea51ff9b1d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* @flow */ | |
| // Types | |
| type ErrorCode = string | number; | |
| type ErrorMessage = string; | |
| // Constants | |
| // 1. Account exists | |
| const accountExistsCodeAndroid: ErrorCode = 'auth/account-exists-with-different-credential'; | |
| const accountExistsCodeIOS: ErrorCode = 17012; | |
| const accountExistsMessage: ErrorMessage = 'It looks like you've already authorised [APPLICATION_NAME] with another provider for this email address. Try logging in again with that provider.'; | |
| // 2. User cancelled operation | |
| const userCancelledCodeAndroid: ErrorCode = 'auth/user-cancelled'; | |
| const userCancelledMessage: ErrorMessage = 'You haven't granted [APPLICATION_NAME] the permissions it needs. Try clicking login again.'; | |
| // 3. User closed popup | |
| const popupClosedCodeAndroid: ErrorCode = 'auth/popup-closed-by-user'; | |
| const popUpClosedMessage: ErrorMessage = 'The Sign In popup was closed before finalizing the operation.'; | |
| // 4. User Not Found | |
| const userNotFoundCodeAndroid: ErrorCode = 'auth/user-not-found'; | |
| const userNotFoundAlternativeCodeAndroid: ErrorCode = 'ERROR_USER_NOT_FOUND'; | |
| const userNotFoundCodeIOS: ErrorCode = 17011; | |
| const userNotFoundMessage: ErrorMessage = 'This email address has no user associated with it. Check that the address is entered correctly, or choose the sign up option to create a new account.'; | |
| // 5. User Disabled | |
| const userDisabledCodeAndroid: ErrorCode = 'auth/user-disabled'; | |
| const userDisabledCodeIOS: ErrorCode = 17005; | |
| const userDisabledMessage: ErrorMessage = 'This user has been disabled'; | |
| // 6. Wrong Password | |
| const wrongPasswordCodeAndroid: ErrorCode = 'auth/wrong-password'; | |
| const wrongPasswordAlternativeCodeAndroid: ErrorCode = 'ERROR_WRONG_PASSWORD'; | |
| const wrongPasswordCodeIOS: ErrorCode = 17009; | |
| const wrongPasswordMessage: ErrorMessage = 'Incorrect password. If you signed up with Facebook, make sure to login with that option.'; | |
| // 7. Invalid Email Format | |
| const invalidEmailFormatCodeAndroid: ErrorCode = 'auth/invalid-email'; | |
| const invalidEmailFormatCodeIOS: ErrorCode = 17008; | |
| const invalidEmailFormatMessage: ErrorMessage = 'Please make sure the email address is correctly formatted'; | |
| // 8. Network timeout | |
| const networkErrorCodeAndroid: ErrorCode = 'auth/network-request-failed'; | |
| const networkErrorCodeIOS: ErrorCode = 17020; | |
| const networkErrorMessage: ErrorMessage = 'A network error (such as timeout, interrupted connection or unreachable host) has occurred.'; | |
| // 9. Weak Password | |
| const weakPasswordCodeAndroid: ErrorCode = 'auth/weak-password'; | |
| const weakPasswordCodeIOS: ErrorCode = 17026; | |
| const weakPasswordMessage: ErrorMessage = 'The password provided isn't strong enough. Please make sure it is alt least 6 characters long'; | |
| // 10. Email already in use | |
| const emailExistsCodeAndroid: ErrorCode = 'auth/email-already-in-use'; | |
| const emailExistsAlternativeCodeAndroid: ErrorCode = 'ERROR_EMAIL_ALREADY_IN_USE'; | |
| const emailExistsCodeIOS: ErrorCode = 17007; | |
| const emailExistsMessage: ErrorMessage = 'This email address already has an account associated with it. Choose the "Login" option rather than "Sign Up"'; | |
| // 11. Account exists with other provider | |
| const existingProviderCodeAndroid: ErrorCode = 'auth/account-exists-with-different-credential'; | |
| const existingProviderCodeIOS: ErrorCode = 17012; | |
| const existingProviderMessage: ErrorMessage = 'Account associated with different login provider. Try logging in with either Facebook or Email, depending on which one you signed up with initially'; | |
| // default | |
| const defaultMessage: ErrorMessage = 'Login failed with unknown error'; | |
| // assignFirebaseError takes firebase web error code and returns an error message as a string | |
| const mapFirebaseError = (code: ErrorCode): ErrorMessage => { | |
| switch (code) { | |
| // 1: | |
| case accountExistsCodeAndroid: | |
| return accountExistsMessage; | |
| case accountExistsCodeIOS: | |
| return accountExistsMessage; | |
| // 2: | |
| case userCancelledCodeAndroid: | |
| return userCancelledMessage; | |
| // 3: | |
| case popupClosedCodeAndroid: | |
| return popUpClosedMessage; | |
| // 4: | |
| case userNotFoundCodeAndroid: | |
| return userNotFoundMessage; | |
| case userNotFoundAlternativeCodeAndroid: | |
| return userNotFoundMessage; | |
| case userNotFoundCodeIOS: | |
| return userNotFoundMessage; | |
| // 5: | |
| case userDisabledCodeAndroid: | |
| return userDisabledMessage; | |
| case userDisabledCodeIOS: | |
| return userDisabledMessage; | |
| // 6: | |
| case wrongPasswordCodeAndroid: | |
| return wrongPasswordMessage; | |
| case wrongPasswordAlternativeCodeAndroid: | |
| return wrongPasswordMessage; | |
| case wrongPasswordCodeIOS: | |
| return wrongPasswordMessage; | |
| // 7: | |
| case invalidEmailFormatCodeAndroid: | |
| return invalidEmailFormatMessage; | |
| case invalidEmailFormatCodeIOS: | |
| return invalidEmailFormatMessage; | |
| // 8: | |
| case networkErrorCodeAndroid: | |
| return networkErrorMessage; | |
| case networkErrorCodeIOS: | |
| return networkErrorMessage; | |
| // 9: | |
| case weakPasswordCodeAndroid: | |
| return weakPasswordMessage; | |
| case weakPasswordCodeIOS: | |
| return weakPasswordMessage; | |
| // 10: | |
| case emailExistsCodeAndroid: | |
| return emailExistsMessage; | |
| case emailExistsAlternativeCodeAndroid: | |
| return emailExistsMessage; | |
| case emailExistsCodeIOS: | |
| return emailExistsMessage; | |
| // 11: | |
| case existingProviderCodeAndroid: | |
| return existingProviderMessage; | |
| case existingProviderCodeIOS: | |
| return existingProviderMessage; | |
| // default | |
| default: | |
| return defaultMessage; | |
| } | |
| }; | |
| export default mapFirebaseError; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment