@flex If your laravel app is running on port 8000, then, you should request to http://localhost:8000
axios.post('http://localhost:8000/api/login', getFormattedCredentials())
.then(() => ...)
also make sure your laravel-app/config/cors.php is configured properly,
return [
'paths' => ['api/*', 'sanctum/csrf-cookie'],
'allowed_origins' => ['*'] // or your origin such as ['http://localhost:3000', 'http://localhost:5173', ...],
// ...
'supports_credentials' => true,
];
and later down the line, you may want to fetch csrf cookie when trying to authenticate,
// predefine base URL
axios.defaults.baseURL = "http://localhost:8000"
// cors and stuff
axios.defaults.withCredentials = true
// axios.defaults.withXSRFToken = true;
const handleLogin = async() => {
try {
// https://laravel.com/docs/10.x/sanctum#csrf-protection
await axios.get('/sanctum/csrf-cookie')
// authenticate
const response = await axios.post('/api/login', getFormattedCredentials())
console.log(response.data)
waitingOnVerification.value = true
}catch(e) {
//
}
}
https://laravel.com/docs/10.x/sanctum#spa-authentication
Hope this helps