mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-04-02 05:23:14 +00:00
rename frontend to web
This commit is contained in:
28
web/projects/ui/src/app/guards/auth.guard.ts
Normal file
28
web/projects/ui/src/app/guards/auth.guard.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
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')),
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user