[Vuejs]-When the page is updated the data is deleted โ€“ vue and laravel sanctum

0๐Ÿ‘

โœ…

I solved it by adding the headers to the axios configuration:

import axios from 'axios'
import store from '@/store/index'

export function http() {
 return axios.create({
 baseURL: store.state.api.apiURL,
 headers: {
   'Content-Type': 'application/json',
   'Accept': 'application/json',
   'Authorization': `Bearer 
   ${localStorage.getItem('accessToken').replace(/['"]+/g, '')}`
  }
 })
}

I get the accessToken from the localstorage and every time the page is reloaded the information is refreshed and does not appear anymore unauthorized

0๐Ÿ‘

sanctum login is depend on cookies not local storage
you must add with_credential: true to axios options
and it is good to use this library to make authintication https://www.npmjs.com/package/vue-sanctum

Leave a comment