loginWithAuthToken static method
Future<User?>
loginWithAuthToken(
- String authToken, {
- required dynamic onSuccess(
- User user
- required dynamic onError(
- CometChatException excep
Returns a User object after login in CometChat API.
The CometChat SDK maintains the session of the logged in user within the SDK. Thus you do not need to call the login method for every session. You can use the CometChat.getLoggedInUser() method to check if there is any existing session in the SDK. This method should return the details of the logged-in user.
Create an Auth Token via the CometChat API for the new user every time the user logs in to your app
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.
method could throw PlatformException with error codes specifying the cause
Implementation
static Future<User?> loginWithAuthToken(String authToken,
{required Function(User user)? onSuccess,
required Function(CometChatException excep)? onError}) async {
try {
final result = await channel.invokeMethod('loginWithAuthToken', {
'authToken': authToken,
});
final User res = User.fromMap(result);
if (onSuccess != null) onSuccess(res);
return res;
} on PlatformException catch (p) {
_errorCallbackHandler(null, p, null, onError);
} catch (e) {
_errorCallbackHandler(null, null, e, onError);
}
return null;
}