mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-03-01 22:00:18 +01:00
🔗 fix: Shared Link with Markdown Code Error (#6016)
* refactor: Export AuthContext from AuthContextProvider * refactor: Update useHasAccess to utilize useContext for AuthContext * refactor: Enhance type definitions in useHasAccess for better type safety
This commit is contained in:
parent
50e8769340
commit
f362f18870
2 changed files with 24 additions and 9 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import { useMemo, useCallback } from 'react';
|
||||
import { PermissionTypes, Permissions } from 'librechat-data-provider';
|
||||
import { useAuthContext } from '~/hooks/AuthContext';
|
||||
import { useMemo, useCallback, useContext } from 'react';
|
||||
import type { TUser, PermissionTypes, Permissions } from 'librechat-data-provider';
|
||||
import { AuthContext } from '~/hooks/AuthContext';
|
||||
|
||||
const useHasAccess = ({
|
||||
permissionType,
|
||||
|
|
@ -9,16 +9,31 @@ const useHasAccess = ({
|
|||
permissionType: PermissionTypes;
|
||||
permission: Permissions;
|
||||
}) => {
|
||||
const { isAuthenticated, user, roles } = useAuthContext();
|
||||
const authContext = useContext(AuthContext);
|
||||
const user = authContext?.user;
|
||||
const roles = authContext?.roles;
|
||||
const isAuthenticated = authContext?.isAuthenticated || false;
|
||||
|
||||
const checkAccess = useCallback(
|
||||
({ user, permissionType, permission }) => {
|
||||
({
|
||||
user,
|
||||
permissionType,
|
||||
permission,
|
||||
}: {
|
||||
user?: TUser | null;
|
||||
permissionType: PermissionTypes;
|
||||
permission: Permissions;
|
||||
}) => {
|
||||
if (!authContext) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isAuthenticated && user?.role != null && roles && roles[user.role]) {
|
||||
return roles[user.role]?.[permissionType]?.[permission] === true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
[isAuthenticated, roles],
|
||||
[authContext, isAuthenticated, roles],
|
||||
);
|
||||
|
||||
const hasAccess = useMemo(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue