pascalboucher / laravel-chatkit-api

Laravel Pusher Chatkit Api wrapper
MIT License
7 stars 3 forks source link

Integrating this with the JS SDK issues #3

Closed BartellDrugs closed 6 years ago

BartellDrugs commented 6 years ago

close this out.

Ravenna commented 6 years ago

My apologies, posted as the wrong user. I have Chatkit up and running with your wrapper. Took a few tries and I can help update the docs to reflect what I had to do (simple stuff).

However to make it a great client experience I need to integrate with the frontend as well. Thankfully Chatkit has this pretty well laid out. the one thing that I need to figure out is:

https://docs.pusher.com/chatkit/reference/javascript#tokenprovider-arguments The token provider in the front end needs to have an Auth solution. Is this already integrated and I don't see it? Or is it needed?

pascalboucher commented 6 years ago

Hi @Ravenna, sorry for the delay.

Yes you can easily integrate this into your frontend using the Chatkit::getToken method. Basically what I would suggest you to do is to make a call to your backend and use this method to return a valid token.

Then, you can use this token and your instance locator to create a valid chatkit user in the frontend.

to get the token : https://github.com/pascalboucher/laravel-chatkit-api/wiki/Tokens

example on how to create a chatkit user in the frontend : https://docs.pusher.com/chatkit/quick_start/javascript#create-a-user

Hope this helps :)

Ravenna commented 6 years ago

@pascalboucher I know you responded about this weeks ago. Just got around to doing it.

In the front end, the ChatKit js tokenProvider takes a url in its options object. It then makes a post request to a url I created using your notes above (thanks BTW).

the issue is that the tokenProvider makes a POST request which fails due to CSRF. I could wrap this whole thing in an axios call but that seems a little over the top.

Any thoughts?

pascalboucher commented 6 years ago

Hey @Ravenna

You need to exclude this url from the csrf protection.

You can see how to do it here : https://laravel.com/docs/5.6/csrf#csrf-excluding-uris

This way, you won't need to use axios for this.