Skip to content

Commit 3016c4e

Browse files
Merge pull request #133 from delphi-hub/feature/checkUserIsAdmin
Feature/checks if user is an admin
2 parents e425791 + 50b6dd7 commit 3016c4e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

client/src/app/api/auth.service.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export const TOKEN_IDENT = 'token';
1111
export class AuthService {
1212

1313
constructor(private apiService: ApiService, public helperService: JwtHelperService) {}
14+
1415
// TODO: store refresh token
1516
login(username: string, password: string) {
1617
return this.apiService.login(username, password).
@@ -19,6 +20,20 @@ export class AuthService {
1920
));
2021
}
2122

23+
userIsAdmin(): boolean {
24+
const rawToken = this.getToken();
25+
if (rawToken && this.isValid()) {
26+
try {
27+
const token = this.helperService.decodeToken(rawToken);
28+
return token.user_type === 'Admin';
29+
} catch {
30+
return false;
31+
}
32+
} else {
33+
return false;
34+
}
35+
}
36+
2237
isValid(): boolean {
2338
// TODO: for dev purpose it will be sufficient to return true here and thereby skipp
2439
// the authorization in the complete application

0 commit comments

Comments
 (0)