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 ofCyberCieraModel
containing API-related configurations.
Function Workflow:
- Initializes
isSuccess
asfalse
. - Calls
ApiManager.get()
with the required method name,privateKey
, andbearerToken
. - Parses the response:
- If the
Message
field in the response is"Verified"
, setsisSuccess = true
.
- If the
- Catches and logs any errors encountered.
- Returns
true
if the token is valid, otherwisefalse
.
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;
}