signupWithCredentials method

  1. @override
Future<Either<Failure, AuthenticationData?>> signupWithCredentials(
  1. AuthSignUpPayload payload
)
override

Implementation

@override
Future<Either<Failure, AuthenticationData?>> signupWithCredentials(AuthSignUpPayload payload) async {
  return wrapAndHandleHttpBaseRequest(
    () {
      final url = config.signupCredentialsAPIendpoint();
      final requestBody = jsonEncode(payload.toMap());
      logger.v("Signup with credentials at API: $url");
      // logger.v("Request body is $requestBody");

      final request = Request(
        "POST",
        url,
      )..body = requestBody;
      return request;
    },
    onResponse: (response, left, right) async {
      AuthenticationData? authData;

      if (config.customSignupCredentialsResponseParser != null) {
        authData = await config.customSignupCredentialsResponseParser!(response.body);
      } else {
        authData = defaultAuthenticationDataParser(response.body)!;
      }

      /// check if we have an authData extracted from response
      /// so we can store the session
      if (authData != null && config.authenticateOnSignup) {
        await storeAuthDataSession(authData);
      }

      logger.v("Login successfully");
      return right(
        authData,
      );
    },
  );
}