Skip to content

Commit

Permalink
Add test and fix error message for unknown multi-factor hint
Browse files Browse the repository at this point in the history
to match the error message produced by the Web.
  • Loading branch information
fzuellich committed Oct 24, 2022
1 parent e38b5c3 commit ce15f02
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,10 @@ public void verifyPhoneNumberWithMultiFactorInfo(
}

if (selectedHint == null) {
rejectPromiseWithCodeAndMessage(promise, "unknown", "Requested multi-factor hint not found.");
rejectPromiseWithCodeAndMessage(
promise,
"multi-factor-info-not-found",
"The user does not have a second factor matching the identifier provided.");
return;
}

Expand Down
28 changes: 28 additions & 0 deletions packages/auth/e2e/multiFactor.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,34 @@ describe('multi-factor', function () {
}
return Promise.reject();
});
it('reports an error when using an unknown factor', async function () {
const { email, password } = await createUserWithMultiFactor();

try {
await firebase.auth().signInWithEmailAndPassword(email, password);
} catch (e) {
e.message.should.equal(
'[auth/multi-factor-auth-required] Please complete a second factor challenge to finish signing into this account.',
);
const resolver = firebase.auth.getMultiFactorResolver(firebase.auth(), e);
const unknownFactor = {
uid: 'notknown',
};
try {
await firebase
.auth()
.verifyPhoneNumberWithMultiFactorInfo(unknownFactor, resolver.session);
} catch (e) {
e.code.should.equal('auth/multi-factor-info-not-found');
e.message.should.equal(
'[auth/multi-factor-info-not-found] The user does not have a second factor matching the identifier provided.',
);

return Promise.resolve();
}
}
return Promise.reject();
});
});

describe('enroll', function () {
Expand Down
12 changes: 11 additions & 1 deletion packages/auth/ios/RNFBAuth/RNFBAuthModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -756,8 +756,17 @@ - (void)invalidate {
}
FIRMultiFactorSession *session = cachedResolver[sessionKey].session;
NSPredicate *findByUid = [NSPredicate predicateWithFormat:@"UID == %@", hintUid];
FIRPhoneMultiFactorInfo *hint =
FIRMultiFactorInfo *_Nullable hint =
[[cachedResolver[sessionKey].hints filteredArrayUsingPredicate:findByUid] firstObject];
if (hint == nil) {
[RNFBSharedUtils rejectPromiseWithUserInfo:reject
userInfo:(NSMutableDictionary *)@{
@"code" : @"multi-factor-info-not-found",
@"message" : @"The user does not have a second factor "
@"matching the identifier provided."
}];
return;
}

[FIRPhoneAuthProvider.provider
verifyPhoneNumberWithMultiFactorInfo:hint
Expand All @@ -772,6 +781,7 @@ - (void)invalidate {
}
}];
}

RCT_EXPORT_METHOD(verifyPhoneNumberForMultiFactor
: (FIRApp *)firebaseApp
: (NSString *)phoneNumber
Expand Down

0 comments on commit ce15f02

Please sign in to comment.