What?
I am currently building a react native app with chatkit, however the authentication seems to fail and keeps bringing back the following message: Instance ID in the path and the access token don't match
I'm using Laravel as a backend and have the following route:
Route::post('/chatkit-auth-user', 'API\MessagesController@authenticateChatkitUser');
Within this method I authenticate the user depending on their user ID like so:
public function authenticateChatkitUser(Request $request)
{
$userId = $request->input('user_id');
$authData = $this->chatkit->authenticate([
'user_id' => "{$userId}",
]);
return response()
->json(
$authData['body'],
$authData['status']
);
}
The token is generate which is then obviously passed into the TokenProvider instance like so:
const url = 'https://my-endpoint.com/api/chatkit-auth-user';
const userToken = this.state.user.authToken;
const tokenProvider = new Chatkit.TokenProvider({
url,
headers: {
Authorization: 'Bearer ' + userToken,
'Content-Type': 'application/json',
},
});
const chatManager = new Chatkit.ChatManager({
instanceLocator: '<MY_INSTANCE_LOCATOR_ID>',
userId: `${this.state.user.userId}`,
tokenProvider: tokenProvider
});
chatManager.connect().then(currentUser => {
this.state.currentUser = currentUser;
console.log(currentUser);
this.currentUser.subscribeToRoom({
roomId: CHATKIT_ROOM_ID,
hooks: {
onNewMessage: this.onReceive.bind(this)
}
});
});
currentUser
never gets consoled and always returns a 403 with the message in the title. From the docs, I think I've implemented everything correctly, I have even span up a heroku app with https://github.com/pusher/chatkit-server-node, the same issue still occurs.
I have spent a couple of days trying to figure this out and would appreciate if I could get some guidance if I'm doing anything wrong!