fix(admin): handle error login status (#7646)

Fix unhandled error login status, modify style

https://github.com/user-attachments/assets/0b40807d-e17a-4d23-a168-4894adfa5998
This commit is contained in:
JimmFly
2024-08-13 05:45:01 +00:00
committed by forehalo
parent b214003968
commit 6dea831d8a
9 changed files with 107 additions and 17 deletions

View File

@@ -6,6 +6,12 @@ import {
import { Separator } from '@affine/admin/components/ui/separator';
import { TooltipProvider } from '@affine/admin/components/ui/tooltip';
import { cn } from '@affine/admin/utils';
import { useQuery } from '@affine/core/hooks/use-query';
import {
FeatureType,
getCurrentUserFeaturesQuery,
serverConfigQuery,
} from '@affine/graphql';
import { AlignJustifyIcon } from 'lucide-react';
import type { ReactNode, RefObject } from 'react';
import {
@@ -17,6 +23,8 @@ import {
useState,
} from 'react';
import type { ImperativePanelHandle } from 'react-resizable-panels';
import { useNavigate } from 'react-router-dom';
import { toast } from 'sonner';
import { Button } from '../components/ui/button';
import {
@@ -114,6 +122,36 @@ export function Layout({ content }: LayoutProps) {
[closePanel, openPanel]
);
const {
data: { serverConfig },
} = useQuery({
query: serverConfigQuery,
});
const {
data: { currentUser },
} = useQuery({
query: getCurrentUserFeaturesQuery,
});
const navigate = useNavigate();
useEffect(() => {
if (serverConfig.initialized === false) {
navigate('/admin/setup');
return;
} else if (!currentUser) {
navigate('/admin/auth');
return;
} else if (!currentUser?.features.includes?.(FeatureType.Admin)) {
toast.error('You are not an admin, please login the admin account.');
navigate('/admin/auth');
return;
}
}, [currentUser, navigate, serverConfig.initialized]);
if (serverConfig.initialized === false || !currentUser) {
return null;
}
return (
<RightPanelContext.Provider
value={{