There are 3 different ways to authenticate a user:
connectUser( { id: USER_ID }, TOKEN ):
{
id: 'user_123',
role: 'user',
created_at: '2022-03-22T21:25:23.091757Z',
updated_at: '2022-03-22T21:25:23.091757Z',
last_active: '2022-03-22T21:25:23.091757Z',
banned: false,
online: true,
invisible: false,
devices: [],
mutes: [],
channel_mutes: [],
unread_count: 0,
total_unread_count: 0,
unread_channels: 0,
language: ''
}
setGuestUser( { id: USER_ID } ):
{
id: 'guest-0cf7eb75-0ef1-49d4-887c-6cd4cb5d4b71-user_123',
role: 'guest',
created_at: '2022-03-22T21:22:57.46579Z',
updated_at: '2022-03-22T21:22:57.46579Z',
last_active: '2022-03-22T21:22:57.793665899Z',
banned: false,
online: true,
invisible: false,
devices: [],
mutes: [],
channel_mutes: [],
unread_count: 0,
total_unread_count: 0,
unread_channels: 0,
language: ''
}
{
id: '!anon',
role: 'anonymous',
created_at: '0001-01-01T00:00:00Z',
updated_at: '0001-01-01T00:00:00Z',
last_active: '2022-03-22T21:18:45.050148582Z',
banned: false,
online: true,
invisible: false,
devices: [],
mutes: [],
channel_mutes: [],
unread_count: 0,
total_unread_count: 0,
unread_channels: 0,
language: ''
}
Each of these methods instantiates a websocket connection to facilitate real-time chat. however, each handle MAU a bit differently.
From the responses to these API calls, you can see the obvious difference between the three are the id & role. The role of your users will determine what sorts of permissions they have. The ID is also reflective of this in the sense that the format will be different depending on the way the user was authenticated ( which is important in regards to how our billing metrics work ).
connectUser() requires a user object with an ID and a JWT signed with the same ID. In this case, if a user who authenticates via this method logs in to your application every day ( 30 ) for a given month, they will count as 1 MAU.
setGuestUser() requires a user object with an ID. Our API will generate a new ID based on the original provided. This means that every time this method is called, even if the provided ID remains the same, a new ID will be generated. In this case, if a user who authenticates via this method logs in to your application every day ( 30 ) for a given month, they will count as 30 MAU.
connectAnonymousUser() requires no additional parameters. The ID of the user who authenticates in this way is always "!anon". In this case, if a user who authenticates via this method logs in to your application every day ( 30 ) for a given month, they will count as 1 MAU. What's unique about connectAnonymousUser() is more in relation to the amount of unique users connecting than an individual doing so over the course of a month. All Anonymous users will count only as 1 MAU total.
Guest & anonymous users certainly have their place in many different circumstances, however they both come with limitations. Two of the most obvious limitations are with permissions and persistence. Additionally, channel membership is not supported for anonymous users. When in doubt, I recommend always using connectUser() unless you have a specific use case that caters to one of the other means of authentication.
Comments
0 comments
Please sign in to leave a comment.