I want to create a middleware to check if token is valid, but the axios cant read. Anyone can help me how to find solution. this si my code:
middleware/authentication.js
export default ({ app, redirect }) => {
let data = {
'userid': app.$cookies.get('user_id'),
'token': app.$cookies.get('auth_token'),
};
app.$axios.post(`/tokenVerify`,data)
.then(res => {
console.log(res)
})
}
pages/index.vue
export default {
middleware: "authentication",
nuxt.config.js
modules: [
'@nuxtjs/axios',
],
axios: {
proxy: true,
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
'Accept' : 'application/json, text/plain, */*',
'Access-Control-Allow-Methods' : 'GET, PUT, POST, DELETE, OPTIONS',
'Access-Control-Allow-Credentials' : true,
}
},
proxy: {
'/tokenVerify':{target:process.env.BASE_URL+'index.php/public/tokenVerify', pathRewrite: {'^/tokenVerify': ''}, changeOrigin: true},
'/vimeoEmbed':{target:'https://vimeo.com/api/oembed.json', pathRewrite: {'^/vimeoEmbed': ''}, changeOrigin: true},
},