validateToken method
Validates the provided bearer token by making an API request.
This function sends a GET request to the validateToken endpoint to verify
whether the provided bearer token is valid. If the API response message is "Verified",
it returns true; otherwise, it returns false.
Parameters:
bearerToken: The authentication token to be validated.cieraModel: An instance ofCyberCieraModelcontaining API credentials.
Function Workflow:
- Initializes
isSuccesstofalse. - Calls
ApiManager.get()with thevalidateTokenendpoint, passing theprivateKeyandbearerTokenas parameters. - Parses the API response:
- If
"Message"is"Verified", setsisSuccesstotrue.
- If
- Catches and logs any errors encountered.
- Returns
isSuccessindicating whether validation was successful.
Returns:
trueif the token is verified.falseif verification fails or an error occurs.
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;
}