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 ofCyberCieraModel
containing API credentials.
Function Workflow:
- Initializes
isSuccess
tofalse
. - Calls
ApiManager.get()
with thevalidateToken
endpoint, passing theprivateKey
andbearerToken
as parameters. - Parses the API response:
- If
"Message"
is"Verified"
, setsisSuccess
totrue
.
- If
- Catches and logs any errors encountered.
- Returns
isSuccess
indicating whether validation was successful.
Returns:
true
if the token is verified.false
if 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;
}