login method
Implementation
Future<ffi.Client> login(String username, String password) async {
// To be removed when client management is implemented.
for (final client in _clients) {
if (client.userId().toString() == username) {
return client;
}
}
String appDocPath = await appDir();
String appCachePath = await appCacheDir();
final client = await _api.loginNewClient(
appDocPath,
appCachePath,
username,
password,
defaultServerName,
defaultServerUrl,
userAgent,
);
if (_clients.length == 1 && _clients[0].isGuest()) {
// we are replacing a guest account
final client = _clients.removeAt(0);
unawaited(
client.logout().catchError((e) {
_log.warning('Logout of Guest failed', e);
return e is int;
}),
); // Explicitly-ignored fire-and-forget.
}
_clients.add(client);
await _persistSessions();
return client;
}