clearKwikpassSession static method
Implementation
static Future<bool> clearKwikpassSession() async {
try {
final userJson =
await cacheInstance.getValue(cdnConfigInstance.getKeys(StorageKeyKeys.gkVerifiedUserKey)!);
final parsedUser =
userJson != null ? jsonDecode(userJson) : <String, dynamic>{'phone': '0'};
final phone = parsedUser['phone']?.toString() ?? '0';
await SnowplowTrackerService.sendCustomEventToSnowPlow({
'category': 'logged_in_page',
'label': 'logout_button_click',
'action': 'automated',
'property': 'phone_number',
'value': int.tryParse(phone) ?? 0,
});
// await trackAnalyticsEvent(AnalyticsEvents.appLogout, {
// 'email': parsedUser['email']?.toString() ?? "",
// 'phone': phone,
// 'customer_id': parsedUser['shopifyCustomerId']?.toString() ?? "",
// });
final env = await cacheInstance.getValue(cdnConfigInstance.getKeys(StorageKeyKeys.gkEnvironmentKey)!);
final mid = await cacheInstance.getValue(cdnConfigInstance.getKeys(StorageKeyKeys.gkMerchantIdKey)!) ?? '';
final isSnowplowTrackingEnabled =
await cacheInstance.getValue(cdnConfigInstance.getKeys(StorageKeyKeys.isSnowplowTrackingEnabled)!) ==
'true';
final isKpEnabled =
await cacheInstance.getValue(cdnConfigInstance.getKeys(StorageKeyKeys.gkKPEnabled)!) ==
'true';
final isCheckoutEnabled =
await cacheInstance.getValue(cdnConfigInstance.getKeys(StorageKeyKeys.gkCheckoutEnabled)!) ==
'true';
final mode =
await cacheInstance.getValue(cdnConfigInstance.getKeys(StorageKeyKeys.gkMode)!);
final gokwik = DioClient().getClient();
gokwik.options.headers.remove(cdnConfigInstance.getHeader(APIHeaderKeys.gkAccessToken)!);
gokwik.options.headers.remove(cdnConfigInstance.getHeader(APIHeaderKeys.checkoutAccessToken)!);
gokwik.options.headers.remove(cdnConfigInstance.getHeader(APIHeaderKeys.kpRequestId)!);
gokwik.options.headers.remove(cdnConfigInstance.getHeader(APIHeaderKeys.gkRequestId)!);
gokwik.options.headers.remove(cdnConfigInstance.getHeader(APIHeaderKeys.authorization)!);
cacheInstance.clearCache();
// final prefs = await SharedPreferences.getInstance();
// await prefs.remove(KeyConfig.gkCoreTokenKey);
// await prefs.remove(KeyConfig.gkAccessTokenKey);
// await prefs.remove(KeyConfig.gkVerifiedUserKey);
// await prefs.remove(KeyConfig.gkRequestIdKey);
// await prefs.remove(KeyConfig.kpRequestIdKey);
// await prefs.remove(KeyConfig.gkAuthTokenKey);
await SecureStorage.clearAllSecureData();
await initializeSdk(InitializeSdkProps(
mid: mid,
environment: Environment.values.firstWhere((e) => e.name == env,
orElse: () => Environment.sandbox),
isSnowplowTrackingEnabled: isSnowplowTrackingEnabled,
mode: mode ?? "",
settings: Settings(
enableKwikPass: isKpEnabled,
enableCheckout: isCheckoutEnabled,
),
));
// Logger().clearLogs();
return true;
} catch (error) {
throw handleApiError(error);
}
}