Have you checked all the configuration ?
https://laravel.com/docs/12.x/sanctum#spa-configuration
Have you also noticed that the back and front have to be on the same top-level domain ?
I have a monolith with web and API routes where the logged-in user accesses a page that makes requests to an API within the system itself. I'm having some questions about how to handle authentication for the API route. What's the best way to handle this?
I put the auth sanctum middleware around the route, but I'm always getting "unauthenticated"
Thats the ajax request i"m doing for it
$(function () { $("#download-form button").on("click", function (e) { e.preventDefault();
let url = $("#download-form input[type='url']").val();
if(!url || !url.startsWith("http")) {
alert("Por favor, insira uma URL válida.");
return;
}
$.ajax({
url: "/api/download/media",
method: "POST",
data: {
url: url,
_token: $("meta[name='csrf-token']").attr("content")
},
success: function (response) {
console.log(response.message);
alert("URL salva com sucesso!");
},
error: function (xhr) {
console.error(xhr.responseText);
alert("Erro ao salvar a URL.");
}
});
});
});
Have you checked all the configuration ?
https://laravel.com/docs/12.x/sanctum#spa-configuration
Have you also noticed that the back and front have to be on the same top-level domain ?
Please or to participate in this conversation.