@@ -73,7 +73,7 @@ class IntercomFlutterWeb extends IntercomFlutterPlatform {
73
73
globalContext.callMethod (
74
74
'Intercom' .toJS,
75
75
'update' .toJS,
76
- { 'user_hash' : userHash} .jsify (),
76
+ updateIntercomSettings ( 'user_hash' , userHash) .jsify (),
77
77
);
78
78
print ("user hash added" );
79
79
}
@@ -93,7 +93,7 @@ class IntercomFlutterWeb extends IntercomFlutterPlatform {
93
93
globalContext.callMethod (
94
94
'Intercom' .toJS,
95
95
'update' .toJS,
96
- { 'user_id' : userId} .jsify (),
96
+ updateIntercomSettings ( 'user_id' , userId) .jsify (),
97
97
);
98
98
// send the success callback only as web does not support the statusCallback.
99
99
statusCallback? .onSuccess? .call ();
@@ -102,7 +102,7 @@ class IntercomFlutterWeb extends IntercomFlutterPlatform {
102
102
globalContext.callMethod (
103
103
'Intercom' .toJS,
104
104
'update' .toJS,
105
- { 'email' : email} .jsify (),
105
+ updateIntercomSettings ( 'email' , email) .jsify (),
106
106
);
107
107
// send the success callback only as web does not support the statusCallback.
108
108
statusCallback? .onSuccess? .call ();
@@ -120,7 +120,7 @@ class IntercomFlutterWeb extends IntercomFlutterPlatform {
120
120
globalContext.callMethod (
121
121
'Intercom' .toJS,
122
122
'update' .toJS,
123
- { 'user_id' : userId} .jsify (),
123
+ updateIntercomSettings ( 'user_id' , userId) .jsify (),
124
124
);
125
125
// send the success callback only as web does not support the statusCallback.
126
126
statusCallback? .onSuccess? .call ();
@@ -213,6 +213,11 @@ class IntercomFlutterWeb extends IntercomFlutterPlatform {
213
213
214
214
@override
215
215
Future <void > logout () async {
216
+ // shutdown will effectively clear out any user data that you have been passing through the JS API.
217
+ // but not from intercomSettings
218
+ // so manually clear some intercom settings
219
+ removeIntercomSettings (['user_hash' , 'user_id' , 'email' ]);
220
+ // shutdown
216
221
globalContext.callMethod ('Intercom' .toJS, 'shutdown' .toJS);
217
222
print ("logout" );
218
223
}
@@ -292,6 +297,35 @@ class IntercomFlutterWeb extends IntercomFlutterPlatform {
292
297
print ("Launched Home space" );
293
298
}
294
299
300
+ @override
301
+ Future <bool > isUserLoggedIn () async {
302
+ // There is no direct JS API available
303
+ // Here we check if intercomSettings has user_id or email then user is
304
+ // logged in
305
+ var settings = getIntercomSettings ();
306
+ var user_id = settings['user_id' ] as String ? ?? "" ;
307
+ var email = settings['email' ] as String ? ?? "" ;
308
+
309
+ return user_id.isNotEmpty || email.isNotEmpty;
310
+ }
311
+
312
+ @override
313
+ Future <Map <String , dynamic >> fetchLoggedInUserAttributes () async {
314
+ // There is no direct JS API available
315
+ // Just return the user_id or email from intercomSettings
316
+ var settings = getIntercomSettings ();
317
+ var user_id = settings['user_id' ] as String ? ?? "" ;
318
+ var email = settings['email' ] as String ? ?? "" ;
319
+
320
+ if (user_id.isNotEmpty) {
321
+ return {'user_id' : user_id};
322
+ } else if (email.isNotEmpty) {
323
+ return {'email' : email};
324
+ }
325
+
326
+ return {};
327
+ }
328
+
295
329
/// get the [window.intercomSettings]
296
330
Map <dynamic , dynamic > getIntercomSettings () {
297
331
if (globalContext.hasProperty ('intercomSettings' .toJS).toDart) {
@@ -316,4 +350,20 @@ class IntercomFlutterWeb extends IntercomFlutterPlatform {
316
350
317
351
return intercomSettings;
318
352
}
353
+
354
+ /// Remove properties from [window.intercomSettings]
355
+ Map <dynamic , dynamic > removeIntercomSettings (List <String > keys) {
356
+ var intercomSettings = getIntercomSettings ();
357
+
358
+ // remove the keys
359
+ for (var key in keys) {
360
+ intercomSettings.remove (key);
361
+ }
362
+
363
+ // Update the [window.intercomSettings]
364
+ globalContext.setProperty (
365
+ "intercomSettings" .toJS, intercomSettings.jsify ());
366
+
367
+ return intercomSettings;
368
+ }
319
369
}
0 commit comments