0

I got a Laravel API with a NextJS frontend, the project is running perfectly well on my Windows computer using WSL. But I can't make it work on my MacBook Pro.

I tried to use Laravel valet using http://backend.test, and I can't log in, I got the following error: Request failed with status code 419 : CSRF token mismatch.

It's probable cause is the domain of the API and the frontend isn't the same, so I tried using PHP artisan serve, so both are on localhost

I'm now able to log in / register and go to every page that makes a request using Axios on the front end. But I got an error o every page that calls Axios using GetServerSideProps :

Error: connect ECONNREFUSED ::1:8000, also i got this error in my console on some page which i don't have on my WSL : xhr.js:143 Refused to set unsafe header "origin"

here is my axios.ts file

import Axios from 'axios'

const axios = Axios.create({
  baseURL: process.env.NEXT_PUBLIC_BACKEND_URL,
  headers: {
    origin: 'localhost:3000',
    'X-Requested-With': 'XMLHttpRequest',
  },
  withCredentials: true,
})

export default axios

UPDATE:

I tried to replace all localhost URL by 127.0.0.1, and now on login i got a 302 not found error and a redirect to /, which return the laravel version and not the user of course. I don't know what cause this redirect

F. Vandroy
  • 122
  • 2
  • 15

0 Answers0