signIn method
- UserLogin? login,
- UserNum? num,
- UserEmail? email,
- UserPhone? phone,
- UserPassword? password,
- ConfirmationCode? code,
- bool unsafe = false,
- bool force = false,
Creates a new Session for the MyUser identified by the provided
num/login/email/phone (exactly one of four should be specified).
The created Session expires in 1 day after creation.
Throws CreateSessionException.
If status is already authorized, then this method does nothing, however,
this logic can be ignored by specifying force as true.
If unsafe is true then this method ignores possible WebUtils.protect
races - you may want to lock it before invoking this method to be
async-safe.
Implementation
Future<void> signIn({
UserLogin? login,
UserNum? num,
UserEmail? email,
UserPhone? phone,
UserPassword? password,
ConfirmationCode? code,
bool unsafe = false,
bool force = false,
}) async {
Log.debug(
'signIn(password: ${password?.obscured}, code: $code, login: $login, num: $num, email: ${email?.obscured}, phone: ${phone?.obscured}, unsafe: $unsafe, force: $force)',
'$runtimeType',
);
// If [ignoreLock] is `true`, then [WebUtils.protect] is ignored.
final Function protect = unsafe ? (fn) => fn() : WebUtils.protect;
status.value = _hasAuthorization
? RxStatus.loadingMore()
: RxStatus.loading();
await protect(() async {
try {
final Credentials creds = await _authRepository.signIn(
password: password,
code: code,
login: num == null ? login : null,
num: num,
email: email,
phone: phone,
);
await _authorized(creds);
status.value = RxStatus.success();
} catch (e) {
if (force) {
status.value = RxStatus.success();
} else {
_unauthorized();
}
rethrow;
}
});
}