Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Joining a twilio channel with a user who already exists

I have a React Native app which uses the Twilio Chat API to connect to a channel. I am using this repo: https://github.com/twilio/TwilioChatJsReactNative

I am using this.generalChannel.join() to join my general channel. This works for any new user.

I have the token generator running in the background as per the documentation in the readme of the repo.

However, when I try to login with an existing user's name, I get an error with the statusText of 'Member already exists'.

How can I log in to my Twilio Chat channel with an existing user?

like image 280
alanbuchanan Avatar asked Jan 02 '23 17:01

alanbuchanan


1 Answers

In the channel object there is a state object. In there is status, which will equal joined if the user is already a member of the channel. Just do something like if(channel.state.status !== "joined") channel.join().

like image 126
cgolding Avatar answered Jan 05 '23 14:01

cgolding