Hello,
I finally succeeded a Fortify / Sanctum / VueJS authentication.
Now I just wanted to share with you what I have done to be sure that my authentication is secure on the VueJS side.
When I log in, I run this code.
async login() {
let user = await apiAuth.login(this.user)
this.$store.commit('auth/setLoggedIn', user)
this.$router.push('/')
}
And the response is retrieve in the store.
setLoggedIn(state, user) {
sessionStorage.setItem('auth', JSON.stringify(user))
state.authenticated = true
state.user = user
},
Then I use a middleware to test if the route is accessible if not authenticated.
{
path: '/students',
name: 'students',
component: Students,
meta: {
requiresAuth: true
}
},
...
router.beforeEach((to, from, next) => {
if (to.matched.some(record => record.meta.requiresAuth)) {
if (!store.getters['auth/isAuthenticated']) {
next({ name: '/login' })
} else {
next()
}
} else {
next()
}
})
Sure I have protected the routes in the back with Laravel.
When I log out, the authenticated and user variables become null in the store.
Is all that secure ?
And another something about what I'm afraid of if that when I log out, the cookies are yet visible (but have their values modified as I log out) in the browser. I thought the cookies are deleted when I log out. Do you really have to be afraid of the cookies ?
Well ... I need some advice to be sure that my code is secure ;).
Thanks for your help ;).
Vincent