Please enable / Bitte aktiviere JavaScript!
Veuillez activer / Por favor activa el Javascript![ ? ]
Why do I receive error 419? - Q&A

Why do I receive error 419?

0 like 0 dislike
Hello! Make the authorization on the project and faced with the fact that when sending data, the server returns 419.
Here is my html code:

Here is the function that is responsible for data transfer:
function auth(){ var email = document.getElementById('email').value; var password = document.getElementById('password').value; var tokenHeader = document.querySelector('meta[name="csrf-token"]').getAttribute('content'); var postdata = new Headers({ 'Content-Type': 'application/json', 'X-CSRF-TOKEN': tokenHeader }); var url = '{!!route('login')!!}'; fetch(url,{ method: 'POST', postdata, body: JSON.stringify({email: email, password:password, ' _token: '{!!csrf_token()!!}'}) }).then((response)=>{ return response.json(); }).then((data)=>{ console.log(data) }).catch((error)=>{ console.log(error) }); }

And here is the response from the server:
asked by | 86 views

2 Answers

0 like 0 dislike
You just added the markup in a hidden field @csrf? The token must otpravlyatsya in the body of the Request each request type (GET exception).
answered by
0 like 0 dislike
Judging by Your two screenshots in kommentariyah, it is clear that the tokens are different. Judging by the js code, it is also 2 different token pass. Do this:
body: JSON.stringify({email: email, password:password, ' _token: tokenHeader})

But, if You use the header token, why would it even during data transfer indicate?
answered by
Welcome to Bug-code Q&A, where you can ask questions and receive answers from other members of the community.

24.8k questions

46.2k answers


12.3k users

24,788 questions
46,220 answers
12,337 users