Frontend implementation of authentication by Laravel Sanctum in Vue Nuxt.JS application.
.ENV config (my config in .env.example):
- AUTH_URL must contains domain with root path of backend (there are the default endpoints of Laravel UI authentication)
- API_URL must contains domain with path to backend api
nuxt.config.js file:
- 'axios.credentials' must be set true (for authentication cookie of course)
- axios automatically places XSRF-TOKEN (from X-XSRF-TOKEN cookie) in Header for any request
- All 'auth.strategies.cookie' endpoints withCredentials must be set true
- 'auth.strategies.cookie.user' property must be set false
# install dependencies
$ npm install
# serve with hot reload at localhost:3000
$ npm run dev
# build for production and launch server
$ npm run build
$ npm run start
# generate static project
$ npm run generate
For detailed explanation on how things work, check out Nuxt.js docs.