loginByEmailAndPassword method

Future<ResponseModel> loginByEmailAndPassword(
  1. EmailPasswordInput body
)

Login by email and password

Implementation

Future<ResponseModel> loginByEmailAndPassword(EmailPasswordInput body) async {
  try {
    String url = '$baseUrl/login/email';
    Response? response = await postx(url, body: json.encode(body));
    ResponseModel data =
        ResponseModel.fromJson(json.decode(response.toString()));
    UserCurrent userCurrent = UserCurrent.fromJson(data.data);
    const storage = FlutterSecureStorage();
    await storage.write(key: 'accessToken', value: userCurrent.accessToken);
    await storage.write(key: 'refreshToken', value: userCurrent.refreshToken);
    return Future.value(data);
  } catch (e) {
    return Future.error(e);
  }
}