diff --git a/client/src/app/api/auth.service.ts b/client/src/app/api/auth.service.ts index fe9a18fc..5ddc1ab7 100644 --- a/client/src/app/api/auth.service.ts +++ b/client/src/app/api/auth.service.ts @@ -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). @@ -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