rodro1

beforeEach vue route auth protector

Jun 26th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.32 KB | None | 0 0
  1. import store from '../vuex'
  2. export const beforeEach = (to, from, next) => {
  3. //next();
  4. store.dispatch('auth/checkTokenExists').then(() => {
  5. if(to.meta.guest){
  6. next({name : 'home'})
  7. return;
  8. }
  9. next();
  10. }).catch(() => {
  11. if(to.meta.needAuth){
  12. next({name : 'login'})
  13. return;
  14. }
  15. next();
  16. })
  17. }
Advertisement
Add Comment
Please, Sign In to add comment