login static method
Future<User?>
login(
- String uid, {
- dynamic onSuccess(
- User user
- dynamic onError(
- CometChatException excep
Use this function only for testing purpose. For production, use loginWithAuthToken
Implementation
static Future<User?> login(String uid,
{Function(User user)? onSuccess,
Function(CometChatException excep)? onError}) async {
if (!checkAuthSettings(onError)) return null;
User? loggedInUser = await getLoggedInUser();
if (loggedInUser == null || loggedInUser.uid != uid) {
User? user = await CometChat.login(uid, authenticationSettings!.authKey!,
onSuccess: (User user) {
getConversationUpdateSettings();
CometChatUIKit.loggedInUser = user;
//executing custom onSuccess handler when user is logged in successfully
if (onSuccess != null) {
try {
onSuccess(user);
} catch (e) {
if (kDebugMode) {
debugPrint(
"user login is successful but failed to execute onSuccess callback");
}
}
}
_initiateAfterLogin();
}, onError: onError);
return user;
} else {
CometChatUIKit.loggedInUser = loggedInUser;
getConversationUpdateSettings();
if (onSuccess != null) {
try {
onSuccess(loggedInUser);
} catch (e) {
if (kDebugMode) {
debugPrint(
"user already logged in but failed to execute onSuccess callback");
}
}
}
_initiateAfterLogin();
return loggedInUser;
}
}