fix(client): continue rendering the page after the authentication check is completed (#6020)

This commit is contained in:
YANG QIA 2025-01-09 08:33:05 +08:00 committed by GitHub
parent a9d30fe330
commit 5f0bceb261
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -11,7 +11,7 @@ import React, { createContext, useContext, useMemo } from 'react';
import { Navigate } from 'react-router-dom';
import { useACLRoleContext } from '../acl';
import { ReturnTypeOfUseRequest, useRequest } from '../api-client';
import { useLocationNoUpdate } from '../application';
import { useAppSpin, useLocationNoUpdate } from '../application';
import { useCompile } from '../schema-component';
export const CurrentUserContext = createContext<ReturnTypeOfUseRequest>(null);
@ -39,10 +39,15 @@ export const useCurrentRoles = () => {
};
export const CurrentUserProvider = (props) => {
const { render } = useAppSpin();
const result = useRequest<any>({
url: 'auth:check',
});
if (result.loading) {
return render();
}
return <CurrentUserContext.Provider value={result}>{props.children}</CurrentUserContext.Provider>;
};