feat: add use current user

This commit is contained in:
jialin
2026-05-07 18:26:48 +08:00
committed by jialin
parent a2d5d55518
commit 4be5fb4d3d
3 changed files with 17 additions and 24 deletions
+11
View File
@@ -0,0 +1,11 @@
import { useModel } from '@@/plugin-model';
export default function useCurrentUser() {
const cu = useModel?.('@@initialState')?.initialState?.currentUser;
if (!cu) return undefined;
return {
...cu,
fullName: cu.full_name ?? cu.fullName,
isAdmin: cu.is_admin ?? cu.isAdmin
};
}
+1 -5
View File
@@ -119,11 +119,7 @@ export const ExtraContent = (props: { isDarkTheme?: boolean }) => {
};
const { initialState } = initialInfo;
const GlobalSettings = pluginManager?.components?.GlobalSettings;
// Plugin slot. A registered plugin can supply an Org switcher via
// components.OrgSwitcher; the host renders nothing when no plugin
// provides it.
const OrgSwitcher = pluginManager?.components?.OrgSwitcher;
const { GlobalSettings, OrgSwitcher } = pluginManager?.components || {};
console.log('plugin+++++++++', pluginManager);
const navigate = useNavigate();
+5 -19
View File
@@ -4,6 +4,7 @@ import DarkMask from '@/components/dark-mask';
import routeCachekey from '@/config/route-cachekey';
import { DEFAULT_ENTER_PAGE, GPUSTACK_API_BASE_URL } from '@/config/settings';
import { COLOR_PRIMARY } from '@/config/theme';
import useCurrentUser from '@/hooks/use-current-user';
import useUserSettings from '@/hooks/use-user-settings';
import useUserSettingsStorage from '@/hooks/use-user-settings-storage';
import useAddResource from '@/pages/dashboard/hooks/use-add-resource';
@@ -133,7 +134,6 @@ export default (props: any) => {
});
const [, contextHolder] = Modal.useModal();
const { themeData, setUserSettings, userSettings } = useUserSettings();
const userSettingsStorage = useUserSettingsStorage();
const [userInfo] = useAtom(userAtom);
const [routeCache] = useAtom(routeCacheAtom);
const location = useLocation();
@@ -346,24 +346,10 @@ export default (props: any) => {
defaultColorPrimary: COLOR_PRIMARY
}}
hooks={{
useUserSettings: useUserSettings,
useUserSettingsStorage: () => userSettingsStorage,
useIntl: useIntl,
// Bridge umi's `@@initialState` model so plugins consuming
// `useCurrentUser` from @gpustack/core-ui get the signed-in
// user without depending on @umijs/max directly. Translate
// the host's snake_case fields to core-ui's camelCase
// `CurrentUser` shape, but pass everything else through so
// hosts can carry extra fields.
useCurrentUser: () => {
const cu = useModel?.('@@initialState')?.initialState?.currentUser;
if (!cu) return undefined;
return {
...cu,
fullName: cu.full_name ?? cu.fullName,
isAdmin: cu.is_admin ?? cu.isAdmin
};
}
useUserSettings,
useUserSettingsStorage,
useIntl,
useCurrentUser
}}
i18n={intl}
locale={{