mirror of
https://github.com/andwati/zitadel.git
synced 2026-10-18 05:52:51 +00:00
* ng 16 * material cdk * module imports, rmn @accounts * deps * lint * buf --------- Co-authored-by: Elio Bischof <[email protected]>
28 lines
790 B
TypeScript
28 lines
790 B
TypeScript
import { Injectable } from '@angular/core';
|
|
import { ActivatedRouteSnapshot, Router, RouterStateSnapshot } from '@angular/router';
|
|
import { Observable } from 'rxjs';
|
|
import { map, tap } from 'rxjs/operators';
|
|
|
|
import { GrpcAuthService } from '../services/grpc-auth.service';
|
|
|
|
@Injectable({
|
|
providedIn: 'root',
|
|
})
|
|
export class UserGuard {
|
|
constructor(private authService: GrpcAuthService, private router: Router) {}
|
|
|
|
public canActivate(
|
|
route: ActivatedRouteSnapshot,
|
|
state: RouterStateSnapshot,
|
|
): Observable<boolean> | Promise<boolean> | boolean {
|
|
return this.authService.user.pipe(
|
|
map((user) => user?.id !== route.params['id']),
|
|
tap((isNotMe) => {
|
|
if (!isNotMe) {
|
|
this.router.navigate(['/users', 'me']);
|
|
}
|
|
}),
|
|
);
|
|
}
|
|
}
|