diff --git a/packages/app-ui/src/layouts/MainBox.tsx b/packages/app-ui/src/layouts/MainBox.tsx index 08211073..ab93687e 100644 --- a/packages/app-ui/src/layouts/MainBox.tsx +++ b/packages/app-ui/src/layouts/MainBox.tsx @@ -68,7 +68,33 @@ const MainBox = () => { }, ); - const { data: meData } = useQuery(MeDocument); + const { data: meData } = useRequest( + () => + axios + .post( + '/graphql', + { + operationName: 'Me', + variables: {}, + query: + 'query Me {\n me {\n id\n username\n password\n nickname\n avatar\n th_refresh_token\n th_access_token\n email\n th_id\n role\n created_at\n __typename\n }\n}', + }, + { + headers: { + Authorization: `Bearer ` + (localStorage.getItem('token') || ''), + }, + }, + ) + .then((res) => res.data), + { + onSuccess(res) { + if (!['/welcome', '/login'].includes(loc.pathname) && !res.data) { + localStorage.clear(); + nav(`/welcome`); + } + }, + }, + ); const nav = useNavigate(); const loc = useLocation(); @@ -166,13 +192,13 @@ const MainBox = () => {
- + - {meData?.me.nickname} + {meData?.data?.me.nickname}