mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-02 22:01:05 +02:00
chore: delete unused useUserAccess hook from use-rbac.ts
This commit is contained in:
parent
74c7e5e7b3
commit
f8ec87c7f2
1 changed files with 0 additions and 69 deletions
|
|
@ -96,75 +96,6 @@ export interface InviteInfo {
|
||||||
|
|
||||||
// ============ Members Hook ============
|
// ============ Members Hook ============
|
||||||
|
|
||||||
export function useUserAccess(searchSpaceId: number) {
|
|
||||||
const [access, setAccess] = useState<UserAccess | null>(null);
|
|
||||||
const [loading, setLoading] = useState(true);
|
|
||||||
const [error, setError] = useState<string | null>(null);
|
|
||||||
|
|
||||||
const fetchAccess = useCallback(async () => {
|
|
||||||
if (!searchSpaceId) return;
|
|
||||||
|
|
||||||
try {
|
|
||||||
setLoading(true);
|
|
||||||
const response = await authenticatedFetch(
|
|
||||||
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/searchspaces/${searchSpaceId}/my-access`,
|
|
||||||
{ method: "GET" }
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
const errorData = await response.json().catch(() => ({}));
|
|
||||||
throw new Error(errorData.detail || "Failed to fetch access info");
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = await response.json();
|
|
||||||
setAccess(data);
|
|
||||||
setError(null);
|
|
||||||
return data;
|
|
||||||
} catch (err: any) {
|
|
||||||
setError(err.message || "Failed to fetch access info");
|
|
||||||
console.error("Error fetching access:", err);
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
}, [searchSpaceId]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
fetchAccess();
|
|
||||||
}, [fetchAccess]);
|
|
||||||
|
|
||||||
// Helper function to check if user has a specific permission
|
|
||||||
const hasPermission = useCallback(
|
|
||||||
(permission: string) => {
|
|
||||||
if (!access) return false;
|
|
||||||
// Owner/full access check
|
|
||||||
if (access.permissions.includes("*")) return true;
|
|
||||||
return access.permissions.includes(permission);
|
|
||||||
},
|
|
||||||
[access]
|
|
||||||
);
|
|
||||||
|
|
||||||
// Helper function to check if user has any of the given permissions
|
|
||||||
const hasAnyPermission = useCallback(
|
|
||||||
(permissions: string[]) => {
|
|
||||||
if (!access) return false;
|
|
||||||
if (access.permissions.includes("*")) return true;
|
|
||||||
return permissions.some((p) => access.permissions.includes(p));
|
|
||||||
},
|
|
||||||
[access]
|
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
|
||||||
access,
|
|
||||||
loading,
|
|
||||||
error,
|
|
||||||
fetchAccess,
|
|
||||||
hasPermission,
|
|
||||||
hasAnyPermission,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// ============ Invite Info Hook (Public) ============
|
|
||||||
|
|
||||||
export function useInviteInfo(inviteCode: string | null) {
|
export function useInviteInfo(inviteCode: string | null) {
|
||||||
const [inviteInfo, setInviteInfo] = useState<InviteInfo | null>(null);
|
const [inviteInfo, setInviteInfo] = useState<InviteInfo | null>(null);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue