Anonymous Users

LAST EDIT Feb 16 2021

If a user is not logged in, you can call the connectAnonymousUser method. While you’re anonymous, you can’t do much, but for the livestream channel type, you’re still allowed to read the chat conversation.

1
2
3
const connectResponse = await client.connectAnonymousUser(); 
 
console.log(connectResponse.me);
1
client.connectAnonymousUser().enqueue(result -> { /* ... */ });
1
2
3
4
5
6
7
8
9
10
import StreamChat 
 
/// 1: Create an anonymous token provider. 
let tokenProvider = TokenProvider.anonymous 
 
/// 2: Create a `ChatClientConfig` with the API key. 
let config = ChatClientConfig(apiKeyString: "YOUR_API_KEY") 
 
/// 3: Create a `ChatClient` instance with the config and the token provider. 
chatClient = ChatClient(config: config, tokenProvider: tokenProvider)
1
client.connectAnonymousUser().enqueue { /*... */ }
1
await client.connectAnonymousUser();

When you connect to chat using anonymously you receive a special user back with the following data:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{ 
	"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.