getUserId()
Gets the current user ID that was set via identify().
Purpose
Retrieves the current user ID that was previously set using identify()
.
Signature
Future<String> getUserId()
Returns / State
Returns a Future<String>
containing the current user ID, or an empty string if no user has been identified.
Usage
Basic usage:
final userId = await Superwall.shared.getUserId();
print('Current user ID: $userId');
Conditional logic:
Future<void> _checkUserStatus() async {
final userId = await Superwall.shared.getUserId();
if (userId.isNotEmpty) {
print('User is logged in: $userId');
// Show personalized content
_loadUserSpecificData();
} else {
print('No user logged in');
// Show login prompt
_showLoginDialog();
}
}
With user attributes:
Future<Map<String, dynamic>> _getCurrentUserInfo() async {
final userId = await Superwall.shared.getUserId();
final attributes = await Superwall.shared.getUserAttributes();
return {
'userId': userId,
'attributes': attributes,
};
}
How is this guide?