( email: string, password: string, onSuccess: (userID: string) => void, onError: (error: any) => void, )
| 52 | * @param onError - callback function to be executed on login error |
| 53 | */ |
| 54 | const login = async ( |
| 55 | email: string, |
| 56 | password: string, |
| 57 | onSuccess: (userID: string) => void, |
| 58 | onError: (error: any) => void, |
| 59 | ) => { |
| 60 | await signInWithEmailAndPassword(auth, email, password) |
| 61 | .then((userCredential) => { |
| 62 | const user = userCredential.user; |
| 63 | |
| 64 | // Check if user email is verified |
| 65 | if (user && !user.emailVerified) { |
| 66 | onError(AuthApiErrorCodes.EMAIL_VERIFICATION_REQUIRED); |
| 67 | return; |
| 68 | } |
| 69 | |
| 70 | localStorage.setItem("user", JSON.stringify(user)); |
| 71 | |
| 72 | // Saves user in the firestore database |
| 73 | // This function is called here and not in signUp to save already existing users in production |
| 74 | createUserInDatabase(user).then(() => { |
| 75 | onSuccess(user.uid); |
| 76 | }); |
| 77 | }) |
| 78 | .catch((error) => { |
| 79 | onError(error); |
| 80 | }); |
| 81 | }; |
| 82 | |
| 83 | /** |
| 84 | * Logout the current user |
nothing calls this directly
no test coverage detected