I've received a token from the backend
axios.post(process.env.VUE_APP_LOGIN, payload)
.then(response => {
const {access_token, token_type, user} = response.data;
this.token = access_token
this.$store.commit('auth/set_Token', access_token)
this.store.commit('auth/set_User', user)
this.$store.commit('auth/set_TokenType', token_type)
axios.defaults.headers.post['Authorization'] = `Bearer ${access_token}`
Now, I want to set up routes for both public and authenticated users.
However, I'm unsure of how to verify and apply the header [authenticated
]
Vue.use(VueRouter)
const routes = [
{
name: 'DataBase',
path: '/table',
component: Table,
},
{
name: 'Home',
path: '/',
component: Main,
},
{
name: 'Login',
path: '/login',
component: Login,
meta: {
public: true,
hideHeader: true,
hideFooter: true,
},
},
{
name: 'Dictionary',
path: '/dovid',
component: Dovid,
meta: {
}
},
]
const router = new VueRouter({
mode: 'history',
base: process.env.BASE_URL,
routes
})
Do I need to use router.beforeEach()? Or is there another method I should be using? Any recommended documentation would be appreciated.