diff --git a/gymboard-api/src/main/java/nl/andrewlalis/gymboard_api/domains/auth/controller/UserController.java b/gymboard-api/src/main/java/nl/andrewlalis/gymboard_api/domains/auth/controller/UserController.java index da846e1..70da333 100644 --- a/gymboard-api/src/main/java/nl/andrewlalis/gymboard_api/domains/auth/controller/UserController.java +++ b/gymboard-api/src/main/java/nl/andrewlalis/gymboard_api/domains/auth/controller/UserController.java @@ -1,6 +1,7 @@ package nl.andrewlalis.gymboard_api.domains.auth.controller; import nl.andrewlalis.gymboard_api.domains.auth.dto.*; +import nl.andrewlalis.gymboard_api.domains.auth.model.Role; import nl.andrewlalis.gymboard_api.domains.auth.model.User; import nl.andrewlalis.gymboard_api.domains.auth.model.UserPreferences; import nl.andrewlalis.gymboard_api.domains.auth.service.UserAccessService; @@ -11,6 +12,9 @@ import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; +import java.util.ArrayList; +import java.util.List; + @RestController public class UserController { private final UserService userService; @@ -156,4 +160,9 @@ public class UserController { userService.reportUser(userId, payload); return ResponseEntity.ok().build(); } + + @GetMapping(path = "/auth/me/roles") + public List getMyRoles(@AuthenticationPrincipal User myUser) { + return myUser.getRoles().stream().map(Role::getShortName).toList(); + } } diff --git a/gymboard-app/src/api/main/auth.ts b/gymboard-app/src/api/main/auth.ts index 079dd14..8d0a024 100644 --- a/gymboard-app/src/api/main/auth.ts +++ b/gymboard-app/src/api/main/auth.ts @@ -1,5 +1,5 @@ import { api } from 'src/api/main/index'; -import { AuthStoreType } from 'stores/auth-store'; +import {AuthStoreType, useAuthStore} from 'stores/auth-store'; import Timeout = NodeJS.Timeout; import { WeightUnit } from 'src/api/main/submission'; import {Page, PaginationOptions, toQueryParams} from "src/api/main/models"; @@ -81,8 +81,14 @@ class AuthModule { authStore.token = await this.getNewToken(credentials); authStore.user = await this.getMyUser(authStore); // Load the user's attached data right away too. - authStore.user.personalDetails = await this.getMyPersonalDetails(authStore); - authStore.user.preferences = await this.getMyPreferences(authStore); + const [personalDetails, preferences, roles] = await Promise.all([ + this.getMyPersonalDetails(authStore), + this.getMyPreferences(authStore), + this.getMyRoles(authStore) + ]); + authStore.user.personalDetails = personalDetails; + authStore.user.preferences = preferences; + authStore.roles = roles; clearTimeout(this.tokenRefreshTimer); this.tokenRefreshTimer = setTimeout( @@ -288,6 +294,11 @@ class AuthModule { authStore.axiosConfig ); } + + public async getMyRoles(authStore: AuthStoreType): Promise { + const response = await api.get('/auth/me/roles', authStore.axiosConfig); + return response.data; + } } export default AuthModule; diff --git a/gymboard-app/src/layouts/MainLayout.vue b/gymboard-app/src/layouts/MainLayout.vue index bcc29fc..3cfbb2e 100644 --- a/gymboard-app/src/layouts/MainLayout.vue +++ b/gymboard-app/src/layouts/MainLayout.vue @@ -37,6 +37,11 @@ Users + + + Admin Panel + + @@ -49,7 +54,9 @@ diff --git a/gymboard-app/src/pages/gym/GymPage.vue b/gymboard-app/src/pages/gym/GymPage.vue index 315f61b..e6782ad 100644 --- a/gymboard-app/src/pages/gym/GymPage.vue +++ b/gymboard-app/src/pages/gym/GymPage.vue @@ -16,15 +16,14 @@