Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help Needed with Device Token Management and Logout in GetStream Integration #843

Closed
keshav-sf opened this issue Jan 29, 2025 · 3 comments
Closed
Assignees

Comments

@keshav-sf
Copy link

Description:
I am integrating GetStream in my app, and I’m facing issues with device token management and user logout. The problem occurs when a user logs in from multiple devices. Calls are being sent to all devices instead of just the active one, and I want to manage the device tokens more effectively.

Problem:

  1. Scenario 1: Handling Login on Multiple Devices
    When a user logs in with the same user ID on different devices, I want to remove all the previous push tokens associated with that user. I’ve tried using the getDevices() and removeDevice() functions, but I am not able to implement this successfully. I want to ensure that when a user logs in on a new device, all old push tokens are removed, preventing the notification from being sent to all devices.

  2. Scenario 2: Logout
    When a user clicks the logout button, I want to remove the current device’s push token from Stream. I am not able to find the correct method to handle this, or I’m unsure how to properly implement it.

What I’ve Tried:

  • I have attempted using the getDevices() method to retrieve devices associated with the user and removeDevice() to delete them, but it doesn’t seem to remove the tokens as expected.
  • I have also tried to implement token removal on logout, but the behavior isn't what I intended.

Expected Behavior:

  • When a user logs in on a new device, the previous device tokens should be cleared.
  • When the user logs out from a device, only the token from that specific device should be removed.

Environment:

  • Stream version: 0.7.1
  • Platform: Both Android and iOS
  • Programming Language: Flutter

Please help me understand how to correctly handle these scenarios with GetStream's API. If there's a better way to approach this, I’d appreciate any guidance or suggestions.

@keshav-sf
Copy link
Author

@Brazol or @deven98 Could you provide help on how to implement it?

@Brazol
Copy link
Contributor

Brazol commented Feb 19, 2025

Hi @keshav-sf,

Your approach using getDevices() and removeDevices() is correct. By default, calling connect() on the StreamVideo instance registers the device token in the backend. If you'd like to handle this manually, you can set registerPushDevice: false when calling connect().

To implement this:

  • After a successful login, call connect(registerPushDevice: false) to connect the user without registering the device.
  • Use getDevices() to retrieve the list of registered devices and call removeDevice() for each to clear outdated ones.
  • Manually register the new device with addDevice().
  • For logout, calling disconnect() will remove the registered device automatically, or you can do so manually with removeDevice().

Let me know if you have any questions!

@Brazol Brazol self-assigned this Feb 19, 2025
@Brazol
Copy link
Contributor

Brazol commented Apr 2, 2025

Hey @keshav-sf, I'm closing this as resolved. Please feel free to reopen it if you still have problems related to this.

@Brazol Brazol closed this as completed Apr 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants