Check Laravel csrf manually in the controller

I am using Laravel 5.5. When I send a POST request from a cuff blade. Then everything is in order:

$.post({ url: 'http://localhost/check', data: { _token: CSRF_TOKEN, // I have CSRF token variable above. test: "it works" } 

But I want to send this request with socket.io> nodejs> laravel:

 socket.emit('checkPost', { token: CSRF_TOKEN }); 

index.js

 socket.on('checkPost', function (csrf) { request.post({ url: 'http://localhost/check', form: { _token: csrf.token, test: "it works" } }); }); 

With ajax, everything is fine. Here I got a token. Why?

When I turn off token verification in VerifyCsrfToken for / check route, then the node request also works.

How can i fix this? Maybe there is a csrf controller validation method? Then I will check the csrf post in the controller .. Thanks in advance and sorry for my bad english.

+5
source share

Source: https://habr.com/ru/post/1272432/


All Articles