Logging Out

LAST EDIT Feb 16 2021

To disconnect a user (say that you’re for instance logging out and logging in as someone new) you can call the disconnect method and repeat the connectUser call as someone else:

1
2
3
4
5
6
7
8
client.disconnect(); 
client.connectUser( 
    { 
        id: 'jack', 
        name: 'Jack Doe', 
    }, 
    'CHAT_USER_TOKEN', 
);
1
2
client.disconnect(); 
client.connectUser(user, token).enqueue(result -> { /* ... */ });
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import StreamChat 
 
// It's impossible to log out a user because the Client instance must always have a user assigned. 
// However, you can simulate this behavior by A: destroying the client instance, or: 
 
// B: Setting the current user as anonymous 
 
chatClient.tokenProvider = .anonymous 
chatClient.currentUserController().reloadUserIfNeeded() 
 
// C: Disconnecting the client 
 
chatClient.connectionController().disconnect() 
 
// when you want to reconnect 
 
chatClient.connectionController().connect { error in 
    if error == nil { 
       // connection successful 
    } 
}
1
2
client.disconnect() 
client.connectUser(user, token).enqueue { /* ... */ }
1
2
3
await client.disconnect(); 
 
await client.setUser(otherUser, "{{ chat_user_token }}");

Disable Push Notifications

Copied!

Additionally, you'll want to stop the user from receiving further push notifications by unregistering their device.