login method
Future<LoginResponse>
login(
- LoginType type, {
- AuthenticationIdentifier? identifier,
- String? password,
- String? token,
- String? deviceId,
- String? initialDeviceDisplayName,
- bool? refreshToken,
- @Deprecated('Deprecated in favour of identifier.') String? user,
- @Deprecated('Deprecated in favour of identifier.') String? medium,
- @Deprecated('Deprecated in favour of identifier.') String? address,
Handles the login and allows the client to call all APIs which require
authentication. Returns false if the login was not successful. Throws
SDNException if login was not successful.
To just login with the username 'alice' you set identifier
to:
AuthenticationUserIdentifier(user: 'alice')
Maybe you want to set user
to the same String to stay compatible with
older server versions.
Implementation
@override
Future<LoginResponse> login(
LoginType type, {
AuthenticationIdentifier? identifier,
String? password,
String? token,
String? deviceId,
String? initialDeviceDisplayName,
bool? refreshToken,
@Deprecated('Deprecated in favour of identifier.') String? user,
@Deprecated('Deprecated in favour of identifier.') String? medium,
@Deprecated('Deprecated in favour of identifier.') String? address,
}) async {
if (node == null) {
final domain = identifier is AuthenticationUserIdentifier
? identifier.user.domain
: null;
if (domain != null) {
await checkNode(Uri.https(domain, ''));
} else {
throw Exception('No node specified!');
}
}
final response = await super.login(
type,
identifier: identifier,
password: password,
token: token,
deviceId: deviceId,
initialDeviceDisplayName: initialDeviceDisplayName,
// ignore: deprecated_member_use
user: user,
// ignore: deprecated_member_use
medium: medium,
// ignore: deprecated_member_use
address: address,
);
// Connect if there is an access token in the response.
final accessToken = response.accessToken;
final deviceId_ = response.deviceId;
final userId = response.userId;
final node_ = node;
if (node_ == null) {
throw Exception('Registered but homerserver is null.');
}
print('login newNode :$node_');
await init(
newToken: accessToken,
newUserID: userId,
newNode: node_,
newDeviceName: initialDeviceDisplayName ?? '',
newDeviceID: deviceId_,
);
return response;
}