From d0f6bca37a40998671406a70edb1e071a1153d15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Niclas=20Str=C3=BCwer?= Date: Thu, 14 Mar 2019 14:24:22 +0100 Subject: [PATCH 1/2] providing userIsAdmin method --- client/src/app/api/auth.service.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/client/src/app/api/auth.service.ts b/client/src/app/api/auth.service.ts index fe9a18fc..10241838 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 From 50b6dd702eb055aa911c8ad37a1771bdae202c12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Niclas=20Str=C3=BCwer?= Date: Thu, 14 Mar 2019 14:24:49 +0100 Subject: [PATCH 2/2] style change --- client/src/app/api/auth.service.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/src/app/api/auth.service.ts b/client/src/app/api/auth.service.ts index 10241838..5ddc1ab7 100644 --- a/client/src/app/api/auth.service.ts +++ b/client/src/app/api/auth.service.ts @@ -24,8 +24,8 @@ export class AuthService { const rawToken = this.getToken(); if (rawToken && this.isValid()) { try { - const token = this.helperService.decodeToken(rawToken); - return token.user_type === 'Admin'; + const token = this.helperService.decodeToken(rawToken); + return token.user_type === 'Admin'; } catch { return false; }