From 27f8c7148af05b5012608722a76acc4cb93054c3 Mon Sep 17 00:00:00 2001 From: Mathis HERRIOT <197931332+0x485254@users.noreply.github.com> Date: Thu, 29 Jan 2026 14:43:01 +0100 Subject: [PATCH] feat: enhance user service with role assignment and frontend scroll-area ref support - Updated `users.service.ts` to assign user roles dynamically based on RBAC. - Enhanced JWT generation to include the user's role in `auth.service.ts`. - Added `viewportRef` prop support to `ScrollArea` component in the frontend for improved flexibility. --- backend/src/auth/auth.service.ts | 1 + backend/src/users/users.service.ts | 28 ++++++++++++++++++++-- frontend/src/components/ui/scroll-area.tsx | 6 ++++- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/backend/src/auth/auth.service.ts b/backend/src/auth/auth.service.ts index f6ad9d2..8b66838 100644 --- a/backend/src/auth/auth.service.ts +++ b/backend/src/auth/auth.service.ts @@ -207,6 +207,7 @@ export class AuthService { const accessToken = await this.jwtService.generateJwt({ sub: user.uuid, username: user.username, + role: user.role, }); return { diff --git a/backend/src/users/users.service.ts b/backend/src/users/users.service.ts index 82fa7ad..a2e8ac3 100644 --- a/backend/src/users/users.service.ts +++ b/backend/src/users/users.service.ts @@ -45,7 +45,19 @@ export class UsersService { } async findByEmailHash(emailHash: string) { - return await this.usersRepository.findByEmailHash(emailHash); + const user = await this.usersRepository.findByEmailHash(emailHash); + if (!user) return null; + + const roles = await this.rbacService.getUserRoles(user.uuid); + return { + ...user, + role: roles.includes("admin") + ? "admin" + : roles.includes("moderator") + ? "moderator" + : "user", + roles, + }; } async findOneWithPrivateData(uuid: string) { @@ -95,7 +107,19 @@ export class UsersService { } async findOne(uuid: string) { - return await this.usersRepository.findOne(uuid); + const user = await this.usersRepository.findOne(uuid); + if (!user) return null; + + const roles = await this.rbacService.getUserRoles(user.uuid); + return { + ...user, + role: roles.includes("admin") + ? "admin" + : roles.includes("moderator") + ? "moderator" + : "user", + roles, + }; } async update(uuid: string, data: UpdateUserDto) { diff --git a/frontend/src/components/ui/scroll-area.tsx b/frontend/src/components/ui/scroll-area.tsx index e1bc7d6..ce015d0 100644 --- a/frontend/src/components/ui/scroll-area.tsx +++ b/frontend/src/components/ui/scroll-area.tsx @@ -8,8 +8,11 @@ import { cn } from "@/lib/utils"; function ScrollArea({ className, children, + viewportRef, ...props -}: React.ComponentProps) { +}: React.ComponentProps & { + viewportRef?: React.Ref; +}) { return ( {children}