mirror of https://github.com/statping/statping
authentication redirect
parent
0413cecdbf
commit
79c60ae6d5
|
@ -53,7 +53,7 @@
|
|||
"babel-loader": "~8.0",
|
||||
"clean-webpack-plugin": "^3.0.0",
|
||||
"compression-webpack-plugin": "~2.0",
|
||||
"cross-env": "~5.2",
|
||||
"cross-env": "^7.0.2",
|
||||
"css-loader": "~2.1",
|
||||
"eslint": "~5.16",
|
||||
"eslint-config-standard": "~10.2",
|
||||
|
|
|
@ -31,9 +31,13 @@ const routes = [
|
|||
meta: {
|
||||
requiresAuth: true
|
||||
},
|
||||
beforeEnter: CheckAuth,
|
||||
children: [{
|
||||
path: '',
|
||||
component: DashboardIndex,
|
||||
meta: {
|
||||
requiresAuth: true
|
||||
}
|
||||
},{
|
||||
path: 'users',
|
||||
component: DashboardUsers
|
||||
|
@ -86,17 +90,22 @@ const router = new VueRouter({
|
|||
routes
|
||||
})
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
function CheckAuth(to, from, next) {
|
||||
if (to.matched.some(record => record.meta.requiresAuth)) {
|
||||
let item = localStorage.getItem("statping_user")
|
||||
let item = localStorage.getItem("statping_user")
|
||||
if (to.path !== '/login' && !item) {
|
||||
next('/login')
|
||||
return
|
||||
}
|
||||
next()
|
||||
const auth = JSON.parse(item)
|
||||
if (!auth.token) {
|
||||
next('/login')
|
||||
return
|
||||
}
|
||||
next()
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export default router
|
||||
|
|
|
@ -3237,12 +3237,12 @@ create-hmac@^1.1.0, create-hmac@^1.1.2, create-hmac@^1.1.4:
|
|||
safe-buffer "^5.0.1"
|
||||
sha.js "^2.4.8"
|
||||
|
||||
cross-env@~5.2:
|
||||
version "5.2.1"
|
||||
resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-5.2.1.tgz#b2c76c1ca7add66dc874d11798466094f551b34d"
|
||||
integrity sha512-1yHhtcfAd1r4nwQgknowuUNfIT9E8dOMMspC36g45dN+iD1blloi7xp8X/xAIDnjHWyt1uQ8PHk2fkNaym7soQ==
|
||||
cross-env@^7.0.2:
|
||||
version "7.0.2"
|
||||
resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-7.0.2.tgz#bd5ed31339a93a3418ac4f3ca9ca3403082ae5f9"
|
||||
integrity sha512-KZP/bMEOJEDCkDQAyRhu3RL2ZO/SUVrxQVI0G3YEQ+OLbRA3c6zgixe8Mq8a/z7+HKlNEjo8oiLUs8iRijY2Rw==
|
||||
dependencies:
|
||||
cross-spawn "^6.0.5"
|
||||
cross-spawn "^7.0.1"
|
||||
|
||||
cross-spawn@^3.0.0:
|
||||
version "3.0.1"
|
||||
|
@ -3263,7 +3263,7 @@ cross-spawn@^6.0.0, cross-spawn@^6.0.5:
|
|||
shebang-command "^1.2.0"
|
||||
which "^1.2.9"
|
||||
|
||||
cross-spawn@^7.0.0:
|
||||
cross-spawn@^7.0.0, cross-spawn@^7.0.1:
|
||||
version "7.0.1"
|
||||
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.1.tgz#0ab56286e0f7c24e153d04cc2aa027e43a9a5d14"
|
||||
integrity sha512-u7v4o84SwFpD32Z8IIcPZ6z1/ie24O6RU3RbtL5Y316l3KuHVPx9ItBgWQ6VlfAFnRnTtMUrsQ9MUUTuEZjogg==
|
||||
|
|
Loading…
Reference in New Issue