validateToken method
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 ofCyberCieraModelcontaining API-related configurations.
Function Workflow:
- Initializes
isSuccessasfalse. - Calls
ApiManager.get()with the required method name,privateKey, andbearerToken. - Parses the response:
- If the
Messagefield in the response is"Verified", setsisSuccess = true.
- If the
- Catches and logs any errors encountered.
- Returns
trueif the token is valid, otherwisefalse.
Returns:
trueif the token is successfully validated.falsein case of failure or an error.
Implementation
Future<bool> validateToken(String bearerToken, CyberSiaraModel 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;
}