clearKwikpassSession static method
Implementation
static Future<bool> clearKwikpassSession() async {
try {
// Get verified user data from storage
final phoneNumber = await cacheInstance.getValue(
cdnConfigInstance.getKeys(StorageKeyKeys.gkVerifiedUserKey)!,
) ?? jsonEncode({});
// Get phone number from storage as fallback
final phoneNumberFromStorage = await cacheInstance.getValue(
cdnConfigInstance.getKeys(StorageKeyKeys.gkUserPhone)!,
);
// Parse verified user data
final parsedUser = jsonDecode(phoneNumber) as Map<String, dynamic>;
final phone = parsedUser['phone']?.toString();
// Send logout event to Snowplow with phone number priority
await SnowplowTrackerService.sendCustomEventToSnowPlow({
'category': 'logged_in_page',
'action': 'logged_out',
'label': 'logout_button_click',
'property': 'phone_number',
'value': phone != null && phone.isNotEmpty
? int.tryParse(phone)
: (phoneNumberFromStorage != null && phoneNumberFromStorage.isNotEmpty
? int.tryParse(phoneNumberFromStorage)
: null),
});
// await trackAnalyticsEvent(AnalyticsEvents.appLogout, {
// 'email': parsedUser['email']?.toString() ?? "",
// 'phone': phone,
// 'customer_id': parsedUser['shopifyCustomerId']?.toString() ?? "",
// });
final results = await Future.wait([
cacheInstance.getValue(cdnConfigInstance.getKeys(StorageKeyKeys.gkEnvironmentKey)!),
cacheInstance.getValue(cdnConfigInstance.getKeys(StorageKeyKeys.gkMerchantIdKey)!),
cacheInstance.getValue(cdnConfigInstance.getKeys(StorageKeyKeys.gkMerchantTypeKey)!),
cacheInstance.getValue(cdnConfigInstance.getKeys(StorageKeyKeys.isSnowplowTrackingEnabled)!),
cacheInstance.getValue(cdnConfigInstance.getKeys(StorageKeyKeys.gkKPEnabled)!),
cacheInstance.getValue(cdnConfigInstance.getKeys(StorageKeyKeys.gkCheckoutEnabled)!),
cacheInstance.getValue(cdnConfigInstance.getKeys(StorageKeyKeys.checkoutMerchantIdKey)!),
cacheInstance.getValue(cdnConfigInstance.getKeys(StorageKeyKeys.checkoutEnvironmentKey)!),
cacheInstance.getValue(cdnConfigInstance.getKeys(StorageKeyKeys.checkoutMerchantTypeKey)!),
cacheInstance.getValue(cdnConfigInstance.getKeys(StorageKeyKeys.gkMode)!),
]);
final kpEnv = results[0];
final kpMid = results[1] ?? '';
final kpMerchantTypeStr = results[2];
final isSnowplowTrackingEnabled = results[3] == 'true';
final isKpEnabled = results[4] == 'true';
final isCheckoutEnabled = results[5] == 'true';
final checkoutMid = results[6] ?? '';
final checkoutEnvStr = results[7];
final checkoutMerchantTypeStr = results[8];
final mode = results[9];
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(
kwikpassConfig: isKpEnabled ? KwikPassConfig(
mid: kpMid,
environment: Environment.values.firstWhere(
(e) => e.name == kpEnv,
orElse: () => Environment.production,
),
merchantType: MerchantType.values.firstWhere(
(e) => e.name == kpMerchantTypeStr,
orElse: () => MerchantType.shopify,
),
isSnowplowTrackingEnabled: isSnowplowTrackingEnabled,
enabled: true,
) : null,
checkoutConfig: isCheckoutEnabled ? CheckoutConfig(
mid: checkoutMid,
environment: Environment.values.firstWhere(
(e) => e.name == checkoutEnvStr,
orElse: () => Environment.production,
),
merchantType: MerchantType.values.firstWhere(
(e) => e.name == checkoutMerchantTypeStr,
orElse: () => MerchantType.shopify,
),
enabled: true,
) : null,
mode: mode ?? '',
));
// Logger().clearLogs();
return true;
} catch (error) {
throw handleApiError(error);
}
}