signIn method
Signs in the given username
with the given password
Implementation
Future<void> signIn(
String username,
String password,
) async {
emit(
state
.startLoading(loginLoading)
.copyWith(awaitingLogin: AuthType.authInProgress),
);
try {
final authType = await provider.signIn(username, password);
final isLoggedIn = authType == AuthType.authDone;
emit(state.copyWith(
user: state.user.copyWith(
username: username,
),
session: isLoggedIn ? state.session.touch() : null,
isLoggedIn: isLoggedIn,
resetAwaitingLogin: isLoggedIn,
// ignored if resetAwaitingLogin is true
awaitingLogin: authType,
));
} on SignInNotAllowedException catch (error, stackTrace) {
emit(
state
.addMessage(
Message.error(_localizations.signInNotAllowed),
error,
stackTrace,
)
.copyWith(resetAwaitingLogin: true),
);
} on SignInException catch (error, stackTrace) {
emit(
state
.addMessage(
Message.error(
_localizations.signInError(error.message),
),
error,
stackTrace,
)
.copyWith(resetAwaitingLogin: true),
);
} finally {
emit(state.endLoading(loginLoading));
}
}