mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2026-09-14 22:24:07 +00:00
get and send system name in AuthenticaionContext to prevent /rest/settings on each render
This commit is contained in:
@@ -23,6 +23,7 @@ const Authentication: FC<RequiredChildrenProps> = ({ children }) => {
|
||||
const [initialized, setInitialized] = useState<boolean>(false);
|
||||
const [me, setMe] = useState<Me>();
|
||||
const [versions, setVersions] = useState<VersionsResponse>();
|
||||
const [systemName, setSystemName] = useState<string>();
|
||||
|
||||
const { send: sendVerifyAuthorization } = useRequest(verifyAuthorization(), {
|
||||
immediate: false
|
||||
@@ -33,7 +34,9 @@ const Authentication: FC<RequiredChildrenProps> = ({ children }) => {
|
||||
{ immediate: false }
|
||||
)
|
||||
.onSuccess((event) => {
|
||||
setVersions(event.data as VersionsResponse);
|
||||
const response = event.data as VersionsResponse;
|
||||
setVersions(response);
|
||||
setSystemName(response.system_name);
|
||||
})
|
||||
.onError(() => {
|
||||
setVersions(undefined);
|
||||
@@ -60,6 +63,7 @@ const Authentication: FC<RequiredChildrenProps> = ({ children }) => {
|
||||
AuthenticationApi.clearAccessToken();
|
||||
setMe(undefined);
|
||||
setVersions(undefined);
|
||||
setSystemName(undefined);
|
||||
if (doRedirect) {
|
||||
void navigate('/', { replace: true });
|
||||
}
|
||||
@@ -96,8 +100,10 @@ const Authentication: FC<RequiredChildrenProps> = ({ children }) => {
|
||||
signOut,
|
||||
refresh,
|
||||
refreshVersions,
|
||||
setSystemName,
|
||||
...(me && { me }),
|
||||
...(versions && { versions })
|
||||
...(versions && { versions }),
|
||||
...(systemName !== undefined && { systemName })
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
|
||||
Reference in New Issue
Block a user