completeSecondFactor method
Presents a code from the account's authenticator, or one recovery code, for the sign-in waiting on it -- or again, as step-up, for this session.
Implementation
Future<DVAuthUser> completeSecondFactor({String? code, String? recoveryCode}) async {
if (code == null && recoveryCode == null) {
throw ArgumentError('A code or a recovery code is required.');
}
const String path = DVAuthEndpoints.secondFactorPath;
final DVHttpResponse response = await _request('POST', path,
body: <String, Object?>{
if (code != null) 'code': code,
if (recoveryCode != null) 'recoveryCode': recoveryCode,
},
bearer: _pendingToken ?? _token);
final Map<String, Object?> json = _decode(response, path);
final DVSession session = _sessionOf(json, path);
final DVAuthUser user = _pendingUser ??
DVAuthUser(
id: session.userId, provider: 'email', createdAt: session.createdAt);
await _adopt(web ? null : json['token'] as String?, session, path);
_pendingUser = null;
_deletionCancelled = json['deletionCancelled'] == true;
return user;
}