Add error page and login error redirection

This commit is contained in:
Chocobozzz
2019-04-01 11:49:54 +02:00
parent 5d8f1297b1
commit ceeb966edd
16 changed files with 187 additions and 30 deletions

View File

@@ -0,0 +1,21 @@
import { NavigationGuard } from 'vue-router';
import { UserRouteName } from '@/router/user';
import { LoginErrorCode } from '@/types/login-error-code.model';
import { AUTH_TOKEN } from '@/constants';
export const authGuardIfNeeded: NavigationGuard = async function (to, from, next) {
if (to.meta.requiredAuth !== true) return next();
// We can't use "currentUser" from apollo here because we may not have loaded the user from the local storage yet
if (!localStorage.getItem(AUTH_TOKEN)) {
return next({
name: UserRouteName.LOGIN,
query: {
code: LoginErrorCode.NEED_TO_LOGIN,
redirect: to.fullPath,
},
});
}
return next();
};