Lots of Bugfixes (#2356)
This commit is contained in:
parent
86e931dd9a
commit
226d6831df
47 changed files with 359 additions and 225 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { CanActivate } from '@angular/router';
|
||||
import {CanActivate, Router} from '@angular/router';
|
||||
import { ToastrService } from 'ngx-toastr';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map, take } from 'rxjs/operators';
|
||||
|
|
@ -11,10 +11,10 @@ import {TranslocoService} from "@ngneat/transloco";
|
|||
})
|
||||
export class AdminGuard implements CanActivate {
|
||||
constructor(private accountService: AccountService, private toastr: ToastrService,
|
||||
private router: Router,
|
||||
private translocoService: TranslocoService) {}
|
||||
|
||||
canActivate(): Observable<boolean> {
|
||||
// this automatically subs due to being router guard
|
||||
return this.accountService.currentUser$.pipe(take(1),
|
||||
map((user) => {
|
||||
if (user && this.accountService.hasAdminRole(user)) {
|
||||
|
|
@ -22,6 +22,7 @@ export class AdminGuard implements CanActivate {
|
|||
}
|
||||
|
||||
this.toastr.error(this.translocoService.translate('toasts.unauthorized-1'));
|
||||
this.router.navigateByUrl('/libraries');
|
||||
return false;
|
||||
})
|
||||
);
|
||||
|
|
|
|||
|
|
@ -22,12 +22,7 @@ export class AuthGuard implements CanActivate {
|
|||
if (user) {
|
||||
return true;
|
||||
}
|
||||
// TODO: Remove the error message stuff here and just redirect them. Don't need to tell them
|
||||
const errorMessage = this.translocoService.translate('toasts.unauthorized-1');
|
||||
const errorMessage2 = this.translocoService.translate('toasts.unauthorized-2');
|
||||
if (this.toastr.toasts.filter(toast => toast.message === errorMessage2 || toast.message === errorMessage).length === 0) {
|
||||
this.toastr.error(errorMessage);
|
||||
}
|
||||
|
||||
localStorage.setItem(this.urlKey, window.location.pathname);
|
||||
this.router.navigateByUrl('/login');
|
||||
return false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue