signIn method

  1. @override
Future<RepositoryResponse<User>> signIn(
  1. String email,
  2. String password
)
override

Implementation

@override
Future<RepositoryResponse<User>> signIn(String email, String password) async {
  try {
    final ResponseModel<AccessResponse> responseModel =
        await ResponseModel.fromApiResponse<AccessResponse>(
      () async => await authApiService.signInUser(
        AccessRequest(
          email: email,
          password: password,
          deviceToken: notificationDeviceToken,
          deviceType: 'mobile',
          platform: Platform.isIOS ? "ios" : 'android',
        ),
      ),
      (body) => AccessResponse.fromJson(body),
    );
    if (responseModel.status == ResponseStatus.success) {
      await TokenManager()
          .setToken(responseModel.response!.data!.accessToken!.token!);
      await UserManager().saveUser(responseModel.response!.data!.user!);
      return RepositoryResponse(
        isSuccess: true,
        data: responseModel.response!.data!.user,
      );
    } else if (responseModel.status == ResponseStatus.responseError ||
        responseModel.status == ResponseStatus.nullResponse) {
      SnackbarManager().showAlertSnackbar(responseModel.error!);
    }
  } on Exception catch (e) {
    ExceptionHandler().handle(e);
  }
  return RepositoryResponse(isSuccess: false);
}