chatClient.connectGuestUser(userId = "bender", username = "Bender").enqueue { /*... */ }chatClient.connectGuestUser(userInfo: .init(id: "john-doe")) { error in
// …
}
// or
let connectedUser = try await chatClient.connectGuestUser(userInfo: .init(id: "john-doe"))
Authless Users
Stream Chat also lets you give unauthenticated users with access to a limited subset of Stream’s capabilities. This is done by using either Guest or Anonymous users.
These two user types are ideal for use cases where users either need to be able to see chat activity prior to authenticating or in scenarios where the additional friction of creating a user account might be unnecessary for a user.
Guest Users
Guest sessions can be created client-side and do not require any server-side authentication. Support and livestreams are common use cases for guests users because really often you want a visitor to be able to use chat on your application without (or before) they have a regular user account.
Guest users are not available to application using multi-tenancy (teams).
Guest users are counted towards your MAU usage.
Guest users have a limited set of permissions. You can read more about how to configure permissions here. You can create a guest user session by using setGuestUser
instead of connectUser
.
You can generate a guest user in a front end client by using the following code:
await client.setGuestUser({ id: 'tommaso' });
chatClient.connectGuestUser(
userInfo: .init(id: "john-doe")
) { error in
// …
}
// or
let connectedUser = try await chatClient.connectGuestUser(
userInfo: .init(id: "john-doe")
)
await chatClient.connectGuestUser(User('id': 'tommaso'));
const FUser User{TEXT("tommaso")};
Client->ConnectGuestUser(
User,
[](const FOwnUser& Guest)
{
// Guest connected
});
client.connectGuestUser("bender", "Bender").enqueue(result -> { /* ... */ });
// Will be implemented soon, open a GitHub issue if you need this feature -> https://github.com/GetStream/stream-chat-unity/issues/
The user object schema is the same as the one described in the Setting the user portion of the docs.
Anonymous Users
If a user is not logged in, you can call the connectAnonymousUser
method. While you’re anonymous, you can’t do much by default, but for the livestream channel type, you’re still allowed to read the chat conversation.
chatClient.connectAnonymousUser().enqueue { /*... */ }chatClient.connectAnonymousUser() { error in
// …
}
// or
let connectedUser = try await chatClient.connectAnonymousUser()
const connectResponse = await client.connectAnonymousUser();
console.log(connectResponse.me);
chatClient.connectAnonymousUser() { error in
// …
}
// or
let connectedUser = try await chatClient.connectAnonymousUser()
await chatClient.connectAnonymousUser();
Client->ConnectAnonymousUser(
[](const FOwnUser& User)
{
// Connected
});
client.connectAnonymousUser().enqueue(result -> { /* ... */ });
// Will be implemented soon, open a GitHub issue if you need this feature -> https://github.com/GetStream/stream-chat-unity/issues/
When you connect to chat using anonymously you receive a special user back with the following data:
{
"id": "!anon",
"role": "anonymous",
"roles": [],
"created_at": "0001-01-01T00:00:00Z",
"updated_at": "0001-01-01T00:00:00Z",
"last_active": "2020-11-02T18:36:01.125136Z",
"banned": false,
"online": true,
"invisible": false,
"devices": [],
"mutes": [],
"channel_mutes": [],
"unread_count": 0,
"total_unread_count": 0,
"unread_channels": 0,
"language": ""
}
Anonymous users are not counted toward your MAU number and only have an impact on the number of concurrent connected clients.
Anonymous users are not allowed to perform any write operations