And also here is one example I use to throw a 403 when using fetch js:
if (!ChkAuth::chklog('user')) { // ignore this line I have custom auth
return response()->json(['message' => 'not auth'], 403);
}
then in fetch:
if (response.status === 403 || response.status === 500) {
response.json().then(function (data) {
var div = document.getElementById('msg');
div.innerHTML += "Not Authorized";
// do your flashy thing here
})
}
@jlrdw I already have tried it ... it doesn't work ... some documents on the web explain that 403 error is not possible with HTTP Exceptions ... I don't understand why.
@snapey I don't show the button ... that's ok ... but I also want to prevent from entering the URL to access the route. What do you mean by saying "ugly FO message" ? I do not find the translation for FO on the web ... ;).
But I also had some trouble, thus is why I have the or 500, it worked.
But being new to fetch js, I am still experimenting. You could also just redirect to a certain page with a friendly error message, many ways to handle this. Even have the page you redirect to show the message "flashy".