From 3b5c3a4675a5c02917760bd1b50b07ba6de0b950 Mon Sep 17 00:00:00 2001 From: Erich N Quintero Date: Wed, 17 May 2023 15:44:09 -0400 Subject: [PATCH 1/2] Refactor AuthProvider to throw original error Refactors the AuthProvider to throw the original error instead of a generic 'Login error: invalid credentials' error. This provides more specific error messages to the user. Specifically, it allows access to the error code needed for MFA sign ins. References: https://firebase.google.com/docs/reference/node/firebase.auth.multifactorerror https://firebase.google.com/docs/auth/web/multi-factor#signing_users_in_with_a_second_factor --- src/providers/AuthProvider.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/providers/AuthProvider.ts b/src/providers/AuthProvider.ts index 63b3456..5eaeb65 100644 --- a/src/providers/AuthProvider.ts +++ b/src/providers/AuthProvider.ts @@ -36,7 +36,7 @@ class AuthClient { return user; } catch (e) { log('HandleAuthLogin: invalid credentials', { params }); - throw new Error('Login error: invalid credentials'); + throw e; } } else { return this.getUserLogin(); From b2515670d86a2b2095f04554859a413c75f84456 Mon Sep 17 00:00:00 2001 From: Erich N Quintero Date: Wed, 17 May 2023 17:14:05 -0400 Subject: [PATCH 2/2] Refactor AuthProvider.ts to handle multi-factor authentication Update the AuthProvider.ts to handle multi-factor authentication while maintaining previous behaviour for all other errors. If the error code is 'auth/multi-factor-auth-required', it logs the second factor challenge required and throws the error. Otherwise, it logs the invalid credentials and throws a generic error message. --- src/providers/AuthProvider.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/providers/AuthProvider.ts b/src/providers/AuthProvider.ts index 5eaeb65..e1c43ef 100644 --- a/src/providers/AuthProvider.ts +++ b/src/providers/AuthProvider.ts @@ -34,9 +34,14 @@ class AuthClient { ); log('HandleAuthLogin: user sucessfully logged in', { user }); return user; - } catch (e) { - log('HandleAuthLogin: invalid credentials', { params }); - throw e; + } catch (e: any) { + if (e.code == 'auth/multi-factor-auth-required') { + log('HandleAuthLogin: second factor challenge required', { params }); + throw e; + } else { + log('HandleAuthLogin: invalid credentials', { params }); + throw new Error('Login error: invalid credentials'); + } } } else { return this.getUserLogin();