auth.js 528 B

1234567891011121314151617181920212223
  1. export default function (context) {
  2. const { route, store, redirect } = context
  3. const isClient = process.client
  4. let path
  5. // console.log('token', token);
  6. // console.log("cookies", cook);
  7. // 在服务端
  8. // 在客户端判读是否需要登陆
  9. if (isClient) {
  10. path = route.path
  11. }
  12. // console.log("path:"+path);
  13. const mainPath = path.split('?')[0]
  14. // console.log('mainPath', mainPath);
  15. if (store.state.user.role !== 'ADMIN' && mainPath.indexOf('/admin') >= 0) {
  16. redirect('/unauthorized')
  17. }
  18. }