Skip to content

Commit 9f05b16

Browse files
committed
export isAuthenticated guard
1 parent 522b0de commit 9f05b16

File tree

2 files changed

+11
-26
lines changed

2 files changed

+11
-26
lines changed
Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,14 @@
1-
import {Injectable} from '@angular/core';
2-
import {
3-
ActivatedRouteSnapshot,
4-
Router,
5-
RouterStateSnapshot,
6-
UrlTree
7-
} from '@angular/router';
8-
import {Observable} from 'rxjs';
1+
import {inject} from '@angular/core';
2+
import {Router} from '@angular/router';
93
import {ConsumerService} from "../service/consumer.service";
104

11-
@Injectable({
12-
providedIn: 'root'
13-
})
14-
export class AuthenticationGuard {
5+
export const isAuthenticated = () => {
6+
const consumer = inject(ConsumerService);
7+
const router = inject(Router);
158

16-
constructor(private consumer: ConsumerService, private router: Router) {
9+
if (consumer.hasValidToken()) {
10+
return true;
11+
} else {
12+
return router.createUrlTree(['login']);
1713
}
18-
19-
isAuthenticated(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
20-
if (this.consumer.hasValidToken()) {
21-
return true;
22-
} else {
23-
return this.router.createUrlTree(['login']);
24-
}
25-
}
26-
27-
}
14+
};

projects/fusio-sdk/src/lib/route/account-route.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@ import {ListComponent as AppListComponent} from '../component/app/list/list.comp
66
import {ListComponent as EventListComponent} from '../component/event/list/list.component';
77
import {SubscriptionComponent} from "../component/subscription/subscription.component";
88
import {CallbackComponent} from "../component/subscription/callback/callback.component";
9-
import {AuthenticationGuard} from "../guard/authentication.guard";
9+
import {isAuthenticated} from "../guard/authentication.guard";
1010

1111
export class AccountRoute {
1212

1313
public static getAll(): Routes {
14-
const isAuthenticated = inject(AuthenticationGuard).isAuthenticated;
15-
1614
return [
1715
{path: '', component: AccountComponent, canActivate: [isAuthenticated] },
1816
{path: 'security', component: SecurityComponent, canActivate: [isAuthenticated] },

0 commit comments

Comments
 (0)