import { Injectable } from '@angular/core'; import { ActivatedRouteSnapshot, CanActivate, GuardResult, MaybeAsync, Router, RouterStateSnapshot } from '@angular/router'; import PocketBase from 'pocketbase'; import { environment } from '../../environments/environment'; @Injectable({ providedIn: 'root' }) export class AuthGuard implements CanActivate { constructor(private router: Router) { }; async canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise { const pb = new PocketBase(environment.POCKETBASE); await pb.collection('users').authRefresh().catch(() => this.router.navigate([''])); if (pb.authStore.isValid) { return true; } this.router.navigate(['']); return false; } }