Skip to content

Commit

Permalink
✨ Add middleware auth to check token in LS
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Briquet committed Oct 14, 2022
1 parent 7817302 commit eb60a63
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/router/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
import { createRouter, createWebHistory } from 'vue-router';
import Home from '@/views/Home.vue';
import Login from '@/views/Login.vue';

// eslint-disable-next-line consistent-return
const auth = () => {
const token = localStorage.getItem('token');
if (token === null) {
return { name: 'Login' };
}
};

const routes = [
{
path: '/',
name: 'Home',
component: Home,
meta: { title: 'Groupomania' },
beforeEnter: [auth],
},
{
path: '/login',
name: 'Login',
Expand Down
9 changes: 9 additions & 0 deletions src/views/Home.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<template>
<div>Accueil</div>
</template>
<script>
export default {
name: 'HomePage',
};
</script>
<style lang=""></style>

0 comments on commit eb60a63

Please sign in to comment.