login method

Future<LoginResponse> login(
  1. String idToken
)

Implementation

Future<LoginResponse> login(String idToken) async {
  final url = Uri.parse('${_wepinBaseUrl}user/login');
  final jsonRequestBody = jsonEncode({'idToken': idToken});
  final response = await http.post(
    url,
    headers: headers,
    body: jsonRequestBody,
  );

  if (response.statusCode >= 200 && response.statusCode < 300) {
    final responseBody = jsonDecode(response.body);
    final res = LoginResponse.fromJson(responseBody);
    setAuthToken(res.token.accessToken, res.token.refreshToken);
    return res;
  } else {
    throw WepinError(WepinErrorCode.failedLogin, 'code: ${response.statusCode} , body: ${response.body}');
  }
}