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.
This commit is contained in:
@@ -207,6 +207,7 @@ export class AuthService {
|
|||||||
const accessToken = await this.jwtService.generateJwt({
|
const accessToken = await this.jwtService.generateJwt({
|
||||||
sub: user.uuid,
|
sub: user.uuid,
|
||||||
username: user.username,
|
username: user.username,
|
||||||
|
role: user.role,
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -45,7 +45,19 @@ export class UsersService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async findByEmailHash(emailHash: string) {
|
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) {
|
async findOneWithPrivateData(uuid: string) {
|
||||||
@@ -95,7 +107,19 @@ export class UsersService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async findOne(uuid: string) {
|
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) {
|
async update(uuid: string, data: UpdateUserDto) {
|
||||||
|
|||||||
@@ -8,8 +8,11 @@ import { cn } from "@/lib/utils";
|
|||||||
function ScrollArea({
|
function ScrollArea({
|
||||||
className,
|
className,
|
||||||
children,
|
children,
|
||||||
|
viewportRef,
|
||||||
...props
|
...props
|
||||||
}: React.ComponentProps<typeof ScrollAreaPrimitive.Root>) {
|
}: React.ComponentProps<typeof ScrollAreaPrimitive.Root> & {
|
||||||
|
viewportRef?: React.Ref<HTMLDivElement>;
|
||||||
|
}) {
|
||||||
return (
|
return (
|
||||||
<ScrollAreaPrimitive.Root
|
<ScrollAreaPrimitive.Root
|
||||||
data-slot="scroll-area"
|
data-slot="scroll-area"
|
||||||
@@ -18,6 +21,7 @@ function ScrollArea({
|
|||||||
>
|
>
|
||||||
<ScrollAreaPrimitive.Viewport
|
<ScrollAreaPrimitive.Viewport
|
||||||
data-slot="scroll-area-viewport"
|
data-slot="scroll-area-viewport"
|
||||||
|
ref={viewportRef}
|
||||||
className="focus-visible:ring-ring/50 size-full rounded-[inherit] transition-[color,box-shadow] outline-none focus-visible:ring-[3px] focus-visible:outline-1"
|
className="focus-visible:ring-ring/50 size-full rounded-[inherit] transition-[color,box-shadow] outline-none focus-visible:ring-[3px] focus-visible:outline-1"
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
|||||||
Reference in New Issue
Block a user