diff --git a/src/components/Header.vue b/src/components/Header.vue
index f3ee794..3971849 100644
--- a/src/components/Header.vue
+++ b/src/components/Header.vue
@@ -40,7 +40,12 @@
- Cerrar sesión
+
+ Cerrar sesión
+
@@ -56,7 +61,13 @@ export default {
return {}
},
methods: {
-
+ logout: function() {
+ localStorage.removeItem('token')
+ localStorage.removeItem('idAdmin')
+ localStorage.removeItem('isAdmin')
+
+ this.$router.push('/login')
+ },
},
}
diff --git a/src/config/config.js b/src/config/config.js
index 3819ca2..90fdb7e 100644
--- a/src/config/config.js
+++ b/src/config/config.js
@@ -1,6 +1,6 @@
-//const config = {
+const config = {
//api: 'https://venus.acatlan.unam.mx/censo-pruebas/',
- //api: 'http://localhost:3000',
-//}
+ api: 'http://localhost:3000',
+}
-//module.exports = config
+module.exports = config
diff --git a/src/routes.js b/src/routes.js
index 12e8135..1f5b89e 100644
--- a/src/routes.js
+++ b/src/routes.js
@@ -14,22 +14,26 @@ const routes = [{
{
path: '/login',
component: Login,
- name: 'login'
+ name: 'login',
+ meta: {isPublic: true}
},
{
path: '/user',
component: User,
- name: 'user'
+ name: 'user',
+ meta: {isPublic:true}
},
{
path: '/addEquip',
component: AddEquip,
- name: 'addEquip'
+ name: 'addEquip',
+ meta: {perm:true}
},
{
path: '/updateEquip',
component: UpdateEquip,
- name: 'updateEquip'
+ name: 'updateEquip',
+ meta: {perm:true}
},
]
@@ -39,4 +43,30 @@ Vue.use(VueRouter)
/* Pruebas */
const router = new VueRouter({ routes })
+const isAuthenticated = function() {
+ return window.localStorage.token ? true : false
+}
+
+const isAdmin = function() {
+ return window.localStorage.isAdmin
+}
+
+//const isAdmon = window.localStorage.getItem('rol') ? true : false
+
+router.beforeEach((to, from, next) => {
+
+ if (to.path !== '/login' && !isAuthenticated()) {
+ // eslint-disable-next-line no-console
+ //console.log("Entrando");
+ return next({name: 'login'})
+ }
+
+ // eslint-disable-next-line no-console
+ if (isAuthenticated() && isAdmin() === false && to.path !== '/user') {
+ return next({name: 'user'})
+ }
+
+ return next()
+})
+
export default router
\ No newline at end of file
diff --git a/src/views/Login.vue b/src/views/Login.vue
index da3bde1..c8efaf3 100644
--- a/src/views/Login.vue
+++ b/src/views/Login.vue
@@ -12,6 +12,7 @@
@@ -27,6 +28,7 @@
@@ -34,7 +36,10 @@
-
@@ -51,31 +56,63 @@