mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-04-01 04:53:40 +00:00
29 lines
717 B
TypeScript
29 lines
717 B
TypeScript
import { Injectable } from '@angular/core'
|
|
import { Router, UrlTree } from '@angular/router'
|
|
import { map, Observable } from 'rxjs'
|
|
import { AuthService } from '../services/auth.service'
|
|
|
|
@Injectable({
|
|
providedIn: 'root',
|
|
})
|
|
export class AuthGuard {
|
|
constructor(
|
|
private readonly authService: AuthService,
|
|
private readonly router: Router,
|
|
) {}
|
|
|
|
canActivate(): Observable<boolean | UrlTree> {
|
|
return this.runAuthCheck()
|
|
}
|
|
|
|
canActivateChild(): Observable<boolean | UrlTree> {
|
|
return this.runAuthCheck()
|
|
}
|
|
|
|
private runAuthCheck(): Observable<boolean | UrlTree> {
|
|
return this.authService.isVerified$.pipe(
|
|
map(verified => verified || this.router.parseUrl('/login')),
|
|
)
|
|
}
|
|
}
|