GithubHelp home page GithubHelp logo

Comments (6)

jonnywilliamson avatar jonnywilliamson commented on July 20, 2024 5

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.

s3rg3 avatar s3rg3 commented on July 20, 2024

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.

jonnywilliamson avatar jonnywilliamson commented on July 20, 2024

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....

#53 (comment)

Perhaps it might help

from laravel-echo-server.

s3rg3 avatar s3rg3 commented on July 20, 2024

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.

s3rg3 avatar s3rg3 commented on July 20, 2024

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.

ahmetugur91 avatar ahmetugur91 commented on July 20, 2024
<script type="text/javascript"> window.Laravel = csrf_token(),]); ?></script>

this one worked for me.

from laravel-echo-server.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.