You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
979 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import { requireLogin } from '~/utils/utils'
export default function ({ store, route, redirect, from }) {
// Every time the route changes (fired on initialization too)
// 如果是注册或者登录则带个redirect参数用于登录后跳转
if (
(route.name === 'login' || route.name === 'register') &&
!(from.name === 'login' || from.name === 'register')
) {
if (!route.query.redirect) {
route.query.redirect = from.fullPath
redirect(route)
return
}
}
store.dispatch('user/checkAndRefreshUser')
const settings = store.getters['setting/settings']
const user = store.getters['user/user']
const permissions = store.getters['user/permissions'] || []
if (requireLogin(settings, user, route, permissions)) {
return redirect('/login')
}
// 如果访问的路由前缀是 /me但是用户没有登录那么跳转到 /login
if (route.path.startsWith('/me') && !user.id) {
return redirect('/login')
}
}