Authentication

Flutter authentication

Applozic User

An Applozic user is the basic entity that is used to identify a real-world user that sends and receives messages.

Creating a user

A user can have many properties. Here is how you can create a user with a display name, user id and password:

dynamic user = {
      'applicationId': "<APPLICATION_ID>",   //Mandatory
      'userId': userId.text,                 //Mandatory
      'displayName': displayName.text,
      'password': password.text,
      'authenticationTypeId': 1              //Mandatory
  };

Login

You can login the user created above with the following method:

ApplozicFlutter.login(user).then((response) {
      print("Login success : " + response)
    }).catchError((error, stack) =>
      print("Error while logging in : " + error.toString()));

🚧

Note

Please remember that you have to log in once and only after you log out must you log in again.

Use code given below to check if the user is logged in:

ApplozicFlutter.isLoggedIn().then((isLoggedIn) {
        if (isLoggedIn) {
          //The user is logged in
         } esle {
          //The user is not logged in
         }
     });

Update logged in user details:

Create a user object with just the details you wish to add/update:

//here as an example we will be updating the display name and adding a image for the user
dynamic user = {
                  'displayName': '<New name>'
                  'imageLink': '<New Image URL>'
                }

Then update the details for the user:

ApplozicFlutter.updateUserDetail(user)
                        .then(
                            (value) => print("User details updated : " + value))
                        .catchError((e, s) => print(
                            "Unable to update user details : " + e.toString()));

Get logged-in user's id

You user is identified by a unique string which we are referring to as it's user-id.
You give a user this id when you create one.

You can get the user-id of the user that is currently logged in to your application by:

ApplozicFlutter.getLoggedInUserId().then((userId) {
      print("Logged in userId : " + userId);
    }).catchError((error, stack) {
      print("User get error : " + error);
   });

What’s Next

Now that we have an authenticated user, we can move to conversations and messaging

Did this page help you?