Skip to content

Commit

Permalink
Implement isUserLoggedIn and fetchLoggedInUserAttributes
Browse files Browse the repository at this point in the history
  • Loading branch information
deepak786 committed Nov 13, 2024
1 parent f54917c commit 8023c32
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,13 @@ void main() {
testWidgets('displayHome', (WidgetTester _) async {
expect(plugin.displayHome(), completes);
});

testWidgets('isUserLoggedIn', (WidgetTester _) async {
expect(plugin.isUserLoggedIn(), completes);
});

testWidgets('fetchLoggedInUserAttributes', (WidgetTester _) async {
expect(plugin.fetchLoggedInUserAttributes(), completes);
});
});
}
29 changes: 29 additions & 0 deletions intercom_flutter_web/lib/intercom_flutter_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,35 @@ class IntercomFlutterWeb extends IntercomFlutterPlatform {
print("Launched Home space");
}

@override
Future<bool> isUserLoggedIn() async {
// There is no direct JS API available
// Here we check if intercomSettings has user_id or email then user is
// logged in
var settings = getIntercomSettings();
var user_id = settings['user_id'] as String? ?? "";
var email = settings['email'] as String? ?? "";

return user_id.isNotEmpty || email.isNotEmpty;
}

@override
Future<Map<String, dynamic>> fetchLoggedInUserAttributes() async {
// There is no direct JS API available
// Just return the user_id or email from intercomSettings
var settings = getIntercomSettings();
var user_id = settings['user_id'] as String? ?? "";
var email = settings['email'] as String? ?? "";

if (user_id.isNotEmpty) {
return {'user_id': user_id};
} else if (email.isNotEmpty) {
return {'email': email};
}

return {};
}

/// get the [window.intercomSettings]
Map<dynamic, dynamic> getIntercomSettings() {
if (globalContext.hasProperty('intercomSettings'.toJS).toDart) {
Expand Down

0 comments on commit 8023c32

Please sign in to comment.