-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
32 lines (30 loc) · 1.21 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import Route from '@ember/routing/route';
import RouterService from '@ember/routing/router-service';
import { service } from '@ember/service';
import { Role } from 'frontend-data-monitoring/constants/roles';
import CurrentSessionService from 'frontend-data-monitoring/services/current-session';
import LoketSessionService from 'frontend-data-monitoring/services/loket-session';
export default class ApplicationRoute extends Route {
@service declare session: LoketSessionService;
@service declare currentSession: CurrentSessionService;
@service declare router: RouterService;
async beforeModel(): Promise<void> {
await this.session.setup();
await this.currentSession.load();
if (this.session.isAuthenticated) {
if (this.currentSession.checkRole(Role.OrgUser)) {
this.router.transitionTo('home.org');
} else if (
this.currentSession.checkRole(Role.SupplierUser) ||
this.currentSession.checkRole(Role.AbbUser)
) {
this.router.transitionTo('home.overview');
} else {
throw new Error(
'Logged in but not with the correct role. Defaulted to public role and there is no content for this type of role.'
);
}
return;
}
}
}