Authenticate a User
Add some users to your app and authenticate via the SDK.
Before we can authenticate a user from our app, we need to create one. You can create a user in either of these 2 ways:
Use the dev panel (the "Users" tab when you select an application) in the Mitter.io Dashboard
Make an API call from your backend server
In this example, we’ll be creating a user from the Mitter.io Dashboard using the dev panel.
Create users from the dashboard
Head over to the Mitter.io Dashboard and do the following:
Select your application from the list
In the left sidebar, click on the Users icon, and then click on New User
Give a name for your user and create one
Since we’ll be creating a group chat channel in the upcoming steps, go ahead and create 2 or 3 more users with different names.
Now, select one of the users you’ve created and click on Add Token. This will create an access token for the user. Copy the access token and keep it handy.
Follow the same process for creating a channel. Just choose the channel type as Group Chat and add all the users that you created in the previous step. Once your channel is created, you’ll see a channel ID. Copy it and keep it handy as well.
Add a user to your app
Go back to your Android project and navigate to your custom Application
class.
First, you need to define a UserAuth
object with the user details you acquired in the previous step.
You can get the user ID from the list of users in the Users tab. Make sure that the ID and auth token both belong to the same user.
Now, just pass this UserAuth
object to your previously configured Mitter
object inside the onCreate()
method in your MyApp
class, like this:
Your Android app is now fully configured to make calls to the Mitter.io Platform. Let’s test that out by fetching some basic information for the currently logged-in user.
Fetch currently logged-in user details
Head over to your MainActivity
and get a reference to the Mitter
object inside the onCreate()
method.
Now, before making any calls, you need to get access to the basic group objects:
Users
Channels
Messaging
Inside your onCreate()
, define 3 objects like this:
You’re now all set to make calls. Let’s test out our setup by making a call to fetch the currently logged-in user details.
You need to call the getCurrentUser()
method on the Users
object that you defined just now.
If you’ve set everything up correctly, you should see something similar to this in your app’s logs:
Last updated