skiarsi wrote a reply+100 XP
5mos ago
this is exactly my problem, after /sanctum/csrf-cookie , Laravel sanctum will change csrf token then on /api/login we need new csrf token because it's change and it will not work fine and always i'll get error. how should I fix this problem?
e.preventDefault();
try {
await axios.get(
`${process.env.NEXT_PUBLIC_BACKEND_URL}/sanctum/csrf-cookie`,
{
withCredentials: true,
}
);
const response = await axios.post(
`${process.env.NEXT_PUBLIC_BACKEND_URL}/api/login/`,
{ email, password },
{
withCredentials: true,
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
}
);
console.log(response);
} catch {
} finally {
}
};```