login method

  1. @override
Future<LoginResponse> login(
  1. LoginType type, {
  2. AuthenticationIdentifier? identifier,
  3. String? password,
  4. String? token,
  5. String? deviceId,
  6. String? initialDeviceDisplayName,
  7. bool? refreshToken,
  8. @Deprecated('Deprecated in favour of identifier.') String? user,
  9. @Deprecated('Deprecated in favour of identifier.') String? medium,
  10. @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;
}