getLoggedInUser static method
Future<User?>
getLoggedInUser({
- dynamic onSuccess(
- User user
- dynamic onError(
- CometChatException excep
Returns logged in User Object
check of getLoggedInUser() function in your app where you check App's user login status. In case it returns nil then you need to call the Login method inside it.
Migration Note: Migrated from platform channels to native Dart implementation. Behavior and signature remain identical for backward compatibility.
Android Reference: CometChat.getLoggedInUser()
Implementation
static Future<User?> getLoggedInUser({
Function(User)? onSuccess,
Function(CometChatException excep)? onError,
}) async {
try {
// Get SDK instance
final sdk = SdkRegistry.getInstance();
// Call native Dart auth repository (synchronous)
// The auth repository returns the full User object with all fields
final user = sdk.auth.getLoggedInUser();
// P9 (design ยง3.3): this used to start the offline layer, which made a
// read accessor the thing that opened the cache. An app that never
// called it never read the kill switch and never opened the store, and
// a call racing a login could tear down an open that was still in
// flight. `SdkInitializer` now starts offline itself, after session
// restore and before the socket connects.
// Call success callback if user exists
if (user != null && onSuccess != null) {
onSuccess(user);
}
return user;
} on SdkException catch (sdkEx) {
// Convert SdkException to CometChatException
final cometChatEx = CometChatException(
sdkEx.code,
sdkEx.details ?? sdkEx.message,
sdkEx.message,
);
_errorCallbackHandler(cometChatEx, null, null, onError);
return null;
} catch (e) {
_errorCallbackHandler(null, null, e, onError);
return null;
}
}