mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-01-30 15:16:45 +08:00
### What problem does this PR solve? Allow superuser(admin) to grant or revoke other superuser. ### Type of change - [x] New Feature (non-breaking change which adds functionality)
56 lines
1.3 KiB
TypeScript
56 lines
1.3 KiB
TypeScript
import { createContext, Dispatch, SetStateAction, useState } from 'react';
|
|
import { Outlet } from 'react-router';
|
|
|
|
import type { IUserInfo } from '@/interfaces/database/user-setting';
|
|
import authorizationUtil from '@/utils/authorization-util';
|
|
|
|
type LocalStoragePersistedUserInfo = {
|
|
avatar: unknown;
|
|
name: string;
|
|
email: string;
|
|
};
|
|
|
|
export type CurrentUserInfo =
|
|
| {
|
|
userInfo: null;
|
|
source: null;
|
|
}
|
|
| {
|
|
userInfo: AdminService.LoginData | IUserInfo;
|
|
source: 'serverRequest';
|
|
}
|
|
| {
|
|
userInfo: LocalStoragePersistedUserInfo;
|
|
source: 'localStorage';
|
|
};
|
|
|
|
const getLocalStorageUserInfo = (): CurrentUserInfo => {
|
|
const userInfo = authorizationUtil.getUserInfoObject();
|
|
|
|
return userInfo
|
|
? {
|
|
userInfo: userInfo,
|
|
source: 'localStorage',
|
|
}
|
|
: {
|
|
userInfo: null,
|
|
source: null,
|
|
};
|
|
};
|
|
|
|
export const CurrentUserInfoContext = createContext<
|
|
[CurrentUserInfo, Dispatch<SetStateAction<CurrentUserInfo>>]
|
|
>([getLocalStorageUserInfo(), () => {}]);
|
|
|
|
const AdminRootLayout = () => {
|
|
const userInfoCtx = useState<CurrentUserInfo>(getLocalStorageUserInfo());
|
|
|
|
return (
|
|
<CurrentUserInfoContext.Provider value={userInfoCtx}>
|
|
<Outlet context={userInfoCtx} />
|
|
</CurrentUserInfoContext.Provider>
|
|
);
|
|
};
|
|
|
|
export default AdminRootLayout;
|