Comments (6)
Not sure if it will help you but in my webpage I have this in my template
<html>
<head>
<meta name="csrf-token" content="{{ csrf_token() }}">
</head>
And everything worked out of the box, I didn't have to add any other code to deal with the csrf token.
from laravel-echo-server.
I also have this in my template but this is not working :(
<meta name="csrf-token" content="{{ csrf_token() }}">
<script type="text/javascript"> window.Laravel = <?php echo json_encode(['csrfToken' => csrf_token(),]); ?></script>
<script type="text/javascript">$.ajaxSetup({headers: { 'X-CSRF-Token' : $('meta[name=csrf-token]').attr('content') }});</script>
Thank you for your help jonnywilliamson
from laravel-echo-server.
You say your public ones are working but the private ones are not?
Does it say you are getting a token mismatch?
Here's a helpful way to debug what is being sent in the websocket. Use google chrome, and open your webpage and open the developer tools (windows F12).
Refresh the page and look at the network menu item. Then click on the WS tab towards the right and look to see if your app make a websocket in the colum.
Select the websocket and then you'll be able to click on the frames tab and watch any and all data being passed from you app to the echo server and vice versa.
Here's a picture of mine in action, you can see the request being sent out with the token included. Perhaps you should check if yours is doing that too....
Perhaps it might help
from laravel-echo-server.
You say your public ones are working but the private ones are not?
Yes, public are working fine because you can suscribe to the channel without requesting authorization to laravel.
But in private you can't suscribe to the channel because you have to request authorization to laravel and it don't work, the csrf token is not added to the request neither the socket-id.
i can send private message, but no one can suscribe on the channel for listenning to them.
Does it say you are getting a token mismatch?
After the launch of the laravel-echo-server in a terminal, for each attempt to subscribe to a private channel i get this error:
null
Could not send authentication request.
(node:8686) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot convert undefined or null to object
in laravel-echo-server/src/channels/private-channel.ts, on line 63 you have :
Log.error(error);
if you change this to:
Log.error(JSON.stringify(body));
you can have the request body of this error, wich is about token mistmatch.
Here's a picture of mine in action, you can see the request being sent out with the token included. Perhaps you should check if yours is doing that too....
i only got 2probe, then 3probe, then 5, then 2, then 3, and it's keep reppeatting 2 and 3.
i'm on https, i should try it with http.
from laravel-echo-server.
i just found why i couldn't have the csrfToken on the websocket.
if you put your app.js in the header laravel-echo can't extract the csrfToken from the view, app.js must be at the end of the view.
from laravel-echo-server.
<script type="text/javascript"> window.Laravel = csrf_token(),]); ?></script>
this one worked for me.
from laravel-echo-server.
Related Issues (20)
- Is the package compromised? HOT 6
- Laravel-echo-server events listeners custom callbacks
- Redis6 ACL Support HOT 1
- 运行一会,就会中断,提示截图显示的错误 HOT 2
- Cannot find module '../dist/cli' - supervisord
- Redis 6 ACL config HOT 1
- Connection refused on docker
- Laravel Echo Server work and client side error only at server HOT 2
- Is there ways to emit data from client (socket.io-client) to laravel-echo-server? HOT 2
- Laravel Echo PresenceChannel vs listen events doesn't work HOT 2
- 使用Laravel 5.8 广播系统,本地研发没有事情,上线后握手阶段,第一次OK,第二次报502,第三次报session id unknown,现在不知道是那个地方出问题了?求帮助 HOT 1
- Is `tlaverdure/laravel-echo-server` abandoned? HOT 6
- Is the cors configuration even working? HOT 1
- echo server socket.io.js error
- support redis cluster
- Redis TTL key is store forever
- CSRF token mismatch after session timeout
- npx laravel-echo-server start HOT 1
- Unable to join channel. Member data for presence channel missing HOT 1
- Is this project compatible with Socket.io v4? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-echo-server.