getBrowserToken static method
Implementation
static Future<Result<dynamic>> getBrowserToken() async {
try {
final goKwik = DioClient().getClient();
final response = (await goKwik.get(cdnConfigInstance.getEndpoint(APIEndpointKeys.getBrowserToken)!)).toBaseResponse();
final data = response.data ?? {};
final requestId = data['requestId'];
final token = data['token'];
final headers = {
cdnConfigInstance.getHeader(APIHeaderKeys.gkRequestId)!: requestId,
cdnConfigInstance.getHeader(APIHeaderKeys.kpRequestId)!: requestId,
cdnConfigInstance.getHeader(APIHeaderKeys.authorization)!: token,
};
goKwik.options.headers.addAll(headers);
await Future.wait([
cacheInstance.setValue(cdnConfigInstance.getKeys(StorageKeyKeys.gkRequestIdKey)!, requestId),
cacheInstance.setValue(cdnConfigInstance.getKeys(StorageKeyKeys.kpRequestIdKey)!, requestId),
cacheInstance.setValue(cdnConfigInstance.getKeys(StorageKeyKeys.gkAuthTokenKey)!, token),
]);
return Success(response.data);
} catch (err) {
throw handleApiError(err);
}
}