connect method

Future<UserLoggedIn> connect(
  1. Credential credential
)
override

Implementation

Future<UserLoggedIn> connect(Credential credential) async {
  try {
    Response resp = await _dio.post("/web/session/authenticate",
        data: _withDefaultParams({
          "db": connection.db,
          "login": credential.username,
          "password": credential.password
        }));
    Map<String, dynamic> _resp = _transformResponse(resp);

    if (resp.headers['set-cookie'] == null) {
      throw Exception(
          "header 'set-cookie' tidak ditemukan. Saat ini tidak bisa running di web, karena https://github.com/flutterchina/dio/issues/1027");
    }
    String sessionId = _getSessionId(resp.headers['set-cookie']!.first);
    UserLoggedIn _user = UserLoggedIn.fromJson(_resp);

    session.update(Session(sessionId, _user));

    return UserLoggedIn.fromJson(_resp);
  } catch (e) {
    if (e is DioError) {
      throw Exception(this._transformDioError(e));
    }

    throw e;
  }
}