Hi there, I'm encountering a problem that I can't seem to solve after a few days of research.
I have a Vue 3 Pinia front-end application in a /vue-cli/queneadmin directory, which is on the port: http://localhost:5173. The back-end is with Laravel Breeze API (sanctum) at /project/quenea, running on the port: http://quenea.test (using Laravel Valet for the project name .test). When I try to test my login, I get an error: POST http://quenea.test/login 419 (unknown status), but when I check the Network, csrf-cookie is 204 and /login is 419. However, when I look in the Application tab, I don't see any cookies..
In my .env configuration, I've done what's necessary as Laravel Breeze has correctly configured the cors.php with credentials set to true.
APP_URL=http://quenea.test
FRONTEND_URL=http://localhost:5173
SESSION_DOMAIN=quenea.test
SANCTUM_STATEFUL_DOMAINS=localhost:5173
SESSION_DRIVER=cookie
Here's my axios config:
import axios from 'axios';
axios.defaults.withCredentials = true;
axios.defaults.withXSRFToken = true;
axios.defaults.baseURL = 'http://quenea.test';
export default axios;
This is my authService.js:
import axios from './axiosConfig';
export const authService = {
async getCsrfCookie() {
await axios.get('/sanctum/csrf-cookie');
},
async login(credentials) {
await this.getCsrfCookie();
return axios.post(`/login`, credentials);
},
....
And my auth store:
...
async login(credentials) {
try {
const response = await authService.login(credentials);
console.log(response)
// this.user = response.data.user;
} catch (error) {
this.error = error.response.data.message;
}
},
...
Finally, my LoginView:
...
const authStore = useAuthStore();
const credentials = reactive({
email: 'test@test',
password: 'password'
})
const error = ref('');
const login = async () => {
await authStore.login(credentials);
error.value = authStore.error;
};