@posiwise/common-services 0.2.14 → 0.2.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -984,10 +984,12 @@ class AuthService {
984
984
  this.integrationsApi = integrationsApi;
985
985
  this.document = document;
986
986
  this.platformSubject = new BehaviorSubject('');
987
+ this.userDataSubject = new BehaviorSubject({});
987
988
  this.twitterEndpoint = '/twitter';
988
989
  this.header_key = 'browser';
989
990
  this.platform = '';
990
991
  this.platform$ = this.platformSubject.asObservable();
992
+ this.userData$ = this.userDataSubject.asObservable();
991
993
  // Set Header Key
992
994
  this.setHeaderKey();
993
995
  }
@@ -1108,11 +1110,12 @@ class AuthService {
1108
1110
  phonegap: true
1109
1111
  };
1110
1112
  }
1111
- // Send DELETE request with token intact, then clear tokens after response
1112
- // Use tap to clear tokens without changing the response stream
1113
1113
  return this.http.delete('session', options).pipe(tap$1(() => {
1114
- // Clear tokens AFTER logout succeeds
1115
1114
  this.secureTokenStorage.clearTokens().subscribe();
1115
+ // Reset Crisp session on logout so next visitor is anonymous again
1116
+ if (window && window.$crisp && typeof window.$crisp.push === 'function') {
1117
+ window.$crisp.push(['do', 'session:reset']);
1118
+ }
1116
1119
  }));
1117
1120
  }
1118
1121
  /**
@@ -1130,6 +1133,23 @@ class AuthService {
1130
1133
  getToken$() {
1131
1134
  return this.secureTokenStorage.getToken$();
1132
1135
  }
1136
+ /**
1137
+ * Get user data (email, name, userId) after login
1138
+ * Similar to getToken$() but returns user information
1139
+ * @returns Observable with user data: { email?: string; name?: string; userId?: string }
1140
+ */
1141
+ getUserData$() {
1142
+ console.log(this.userData$);
1143
+ return this.userData$;
1144
+ }
1145
+ /**
1146
+ * Set user data in the BehaviorSubject
1147
+ * Called after user logs in to update user information across the app
1148
+ * @param userData User data object with email, name, and userId
1149
+ */
1150
+ setUserData(userData) {
1151
+ this.userDataSubject.next(userData);
1152
+ }
1133
1153
  getNewsletterSubscription(token) {
1134
1154
  return this.http.get(`${NEWSLETTER_CONFIRMATION_PATH}?token=${token}`);
1135
1155
  }
@@ -1195,13 +1215,33 @@ class AuthService {
1195
1215
  return this.userService.getUserInfo();
1196
1216
  }));
1197
1217
  sequence$.subscribe(resp => {
1198
- // Store user information in localStorage for chat widgets and other services
1199
- const firstName = resp.first_name || '';
1200
- const email = resp.email || '';
1201
- const userId = resp.id?.toString() || '';
1218
+ const firstName = resp.first_name ?? '';
1219
+ const email = resp.email ?? '';
1220
+ const userId = resp.id?.toString() ?? '';
1202
1221
  localStorage.setItem('name', firstName);
1203
1222
  localStorage.setItem('userEmail', email);
1204
1223
  localStorage.setItem('userId', userId);
1224
+ this.setUserData({
1225
+ name: firstName,
1226
+ email: email,
1227
+ userId: userId
1228
+ });
1229
+ // Identify logged-in user in Crisp if widget is already loaded
1230
+ if (window && window.$crisp && typeof window.$crisp.push === 'function') {
1231
+ if (email) {
1232
+ window.$crisp.push(['set', 'user:email', email]);
1233
+ }
1234
+ if (firstName) {
1235
+ window.$crisp.push(['set', 'user:nickname', firstName]);
1236
+ }
1237
+ if (userId) {
1238
+ window.$crisp.push([
1239
+ 'set',
1240
+ 'session:data',
1241
+ [['user_id', [userId]]]
1242
+ ]);
1243
+ }
1244
+ }
1205
1245
  this.router.navigate(['home']);
1206
1246
  if ($('.cc-dismiss').length > 0) {
1207
1247
  $('.cc-dismiss')[0].click();