Skip to content

Commit

Permalink
feat: 登录优化
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangtao25 committed Nov 1, 2023
1 parent 59e6062 commit 99de329
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions packages/app-ui/src/layouts/MainBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,33 @@ const MainBox = () => {
},
);

const { data: meData } = useQuery(MeDocument);
const { data: meData } = useRequest(
() =>
axios
.post<any>(
'/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();
Expand Down Expand Up @@ -166,13 +192,13 @@ const MainBox = () => {
<Dropdown menu={{ items, onClick }}>
<div>
<HoverEffect>
<Avatar size={'small'} src={meData?.me.avatar} />
<Avatar size={'small'} src={meData?.data?.me.avatar} />
<span
css={css`
margin-left: 6px;
`}
>
{meData?.me.nickname}
{meData?.data?.me.nickname}
</span>
</HoverEffect>
</div>
Expand Down

0 comments on commit 99de329

Please sign in to comment.