validateToken method

Future<bool> validateToken(
  1. String bearerToken,
  2. CyberCieraModel cieraModel
)

Validates the authentication token received from the API.

This function sends a GET request to the validateToken endpoint with the provided bearerToken and the privateKey from cieraModel. If the response message is "Verified", the function returns true, indicating a successful token validation.

Parameters:

  • bearerToken: The authentication token to be validated.
  • cieraModel: An instance of CyberCieraModel containing API-related configurations.

Function Workflow:

  1. Initializes isSuccess as false.
  2. Calls ApiManager.get() with the required method name, privateKey, and bearerToken.
  3. Parses the response:
    • If the Message field in the response is "Verified", sets isSuccess = true.
  4. Catches and logs any errors encountered.
  5. Returns true if the token is valid, otherwise false.

Returns:

  • true if the token is successfully validated.
  • false in case of failure or an error.

Implementation

Future<bool> validateToken(String bearerToken, CyberCieraModel cieraModel) async {
  bool isSuccess = false;
  try {
    ResponseAPI responseAPI =
        await ApiManager.get(methodName: ApiConstant.validateToken, privateKey: cieraModel.privateKey, bearerToken: bearerToken);
    Map<String, dynamic> valueMap = responseAPI.response;
    if (valueMap["Message"] == "Verified") {
      isSuccess = true;
    }
  } catch (err) {
    error(err.toString());
  }
  return isSuccess;
}