mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 12:37:20 +00:00
Enhance authentication and authorization components
- Refactored `AppAuth` to introduce `getGuardContextSchema` for improved user context handling. - Updated `Authenticator` to utilize `pickKeys` for user data extraction in JWT generation. - Enhanced `Guard` class to improve permission checks and error handling. - Modified `SystemController` to return context schema alongside permissions in API responses. - Added new `permissions` method in `SystemApi` for fetching permissions. - Improved UI components with additional props and tooltip support for better user experience.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import type { Api } from "Api";
|
||||
import { FetchPromise, type ModuleApi, type ResponseObject } from "modules/ModuleApi";
|
||||
import useSWR, { type SWRConfiguration, useSWRConfig } from "swr";
|
||||
import useSWR, { type SWRConfiguration, useSWRConfig, type Middleware, type SWRHook } from "swr";
|
||||
import useSWRInfinite from "swr/infinite";
|
||||
import { useApi } from "ui/client";
|
||||
import { useState } from "react";
|
||||
@@ -89,3 +89,25 @@ export const useInvalidate = (options?: { exact?: boolean }) => {
|
||||
return mutate((k) => typeof k === "string" && k.startsWith(key));
|
||||
};
|
||||
};
|
||||
|
||||
const mountOnceCache = new Map<string, any>();
|
||||
|
||||
/**
|
||||
* Simple middleware to only load on first mount.
|
||||
*/
|
||||
export const mountOnce: Middleware = (useSWRNext: SWRHook) => (key, fetcher, config) => {
|
||||
if (typeof key === "string") {
|
||||
if (mountOnceCache.has(key)) {
|
||||
return useSWRNext(key, fetcher, {
|
||||
...config,
|
||||
revalidateOnMount: false,
|
||||
});
|
||||
}
|
||||
const swr = useSWRNext(key, fetcher, config);
|
||||
if (swr.data) {
|
||||
mountOnceCache.set(key, true);
|
||||
}
|
||||
return swr;
|
||||
}
|
||||
return useSWRNext(key, fetcher, config);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user