login static method

Future<LoginSession> login({
  1. required UserIdentifier identifier,
  2. required String password,
})

Implementation

static Future<LoginSession> login({
  required UserIdentifier identifier,
  required String password,
}) async {
  HeraRequest req = HeraRequest()..namespace = _namespace;
  User user = userWithIdentifiers(identifier);
  req.user = user;
  user.password = Hash(body: password);
  // analytical information about token
  Token token = Token();
  token.deviceInfo = await HeraExtenstion.getDeviceInfo();
  req.token = token;
  try {
    HeraResponse resp = await _heraClient.login(req);
    if (resp.loginSession.loginStatus != LoginStatus.AUTHENTICATED) {
      return resp.loginSession;
    }
    if (resp.token.accessToken == "" || resp.token.refreshToken == "") {
      throw Exception("token is null. Contact info@nuntio.io");
    }
    if (resp.user.id == "") {
      throw Exception("user is null. Contact info@nuntio.io");
    }
    _setCurrentUser(resp.user);
    _setAccessToken(resp.token.accessToken);
    _setRefreshToken(resp.token.refreshToken);
  } catch (e) {
    if (kDebugMode) {
      print("could not login user: $e");
    }
    rethrow;
  }
  onAuthenticated();
  return LoginSession()..loginStatus = LoginStatus.AUTHENTICATED;
}