first draft
This commit is contained in:
15
src/app/auth-guard.ts
Normal file
15
src/app/auth-guard.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { inject, Injectable } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot } from '@angular/router';
|
||||
import { environment } from '../environments/environment';
|
||||
|
||||
@Injectable()
|
||||
export class AuthGuard implements CanActivate {
|
||||
private readonly router = inject(Router);
|
||||
|
||||
canActivate(_route: ActivatedRouteSnapshot, _state: RouterStateSnapshot): boolean {
|
||||
const token = environment.apiKey??localStorage.getItem('api-key');
|
||||
if (!environment.production && !token)
|
||||
this.router.navigate(['login'], { queryParams: { redirectTo: btoa(window.location.pathname + window.location.search) } });
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user