Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions client/src/app/api/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const TOKEN_IDENT = 'token';
export class AuthService {

constructor(private apiService: ApiService, public helperService: JwtHelperService) {}

// TODO: store refresh token
login(username: string, password: string) {
return this.apiService.login(username, password).
Expand All @@ -19,6 +20,20 @@ export class AuthService {
));
}

userIsAdmin(): boolean {
const rawToken = this.getToken();
if (rawToken && this.isValid()) {
try {
const token = this.helperService.decodeToken(rawToken);
return token.user_type === 'Admin';
} catch {
return false;
}
} else {
return false;
}
}

isValid(): boolean {
// TODO: for dev purpose it will be sufficient to return true here and thereby skipp
// the authorization in the complete application
Expand Down