new auth, hot entries
This commit is contained in:
+14
-11
@@ -1,7 +1,7 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
|
||||
import { AuthService } from '../services/auth.service';
|
||||
import { AuthService, RequestError } from '../services/auth.service';
|
||||
import { UserService } from '../services/user.service';
|
||||
import { I18nService } from '../services/i18n.service';
|
||||
|
||||
@@ -29,6 +29,10 @@ export class AuthGuard implements CanActivate {
|
||||
return this.authService.getAuth().then(response => {
|
||||
return true;
|
||||
}).catch(function (error) {
|
||||
if (error instanceof RequestError && (error as RequestError).getResponse().status == 401) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return that.router.navigateByUrl(that.router.parseUrl('/unavailable?target=' + next.url), { skipLocationChange: true });
|
||||
});
|
||||
}
|
||||
@@ -43,10 +47,6 @@ export class AuthenticatedGuard implements CanActivate {
|
||||
canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
|
||||
const that = this;
|
||||
return this.authService.getAuth().then((data: any) => {
|
||||
if (!data || !data.authenticated) {
|
||||
return that.router.navigateByUrl(that.router.parseUrl('/login?target=' + encodeURIComponent(state.url)), { skipLocationChange: true, replaceUrl: true });
|
||||
}
|
||||
|
||||
this.userService.get().subscribe((user: any) => {
|
||||
let updateLocale = false;
|
||||
let updateTheme = false;
|
||||
@@ -72,9 +72,12 @@ export class AuthenticatedGuard implements CanActivate {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return true;
|
||||
}).catch(function (error) {
|
||||
if (error instanceof RequestError && (error as RequestError).getResponse().status == 401) {
|
||||
return that.router.navigateByUrl(that.router.parseUrl('/login?target=' + encodeURIComponent(state.url)), { skipLocationChange: true, replaceUrl: true });
|
||||
}
|
||||
|
||||
return that.router.navigateByUrl(that.router.parseUrl('/unavailable?target=' + next.url), { skipLocationChange: true });
|
||||
});
|
||||
}
|
||||
@@ -89,12 +92,12 @@ export class AnonymousGuard implements CanActivate {
|
||||
canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
|
||||
const that = this;
|
||||
return this.authService.getAuth().then((data: any) => {
|
||||
if (data && data.authenticated) {
|
||||
this.router.navigateByUrl('/');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
this.router.navigateByUrl('/');
|
||||
return false;
|
||||
}).catch(function (error) {
|
||||
if (error instanceof RequestError && (error as RequestError).getResponse().status == 401) {
|
||||
return true;
|
||||
}
|
||||
return that.router.navigateByUrl(that.router.parseUrl('/unavailable?target=' + next.url), { replaceUrl: true });
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user