fix: no throw exception when request users:check

This commit is contained in:
chenos 2022-04-12 22:45:56 +08:00
parent d7856e76ab
commit 2af045979f
2 changed files with 3 additions and 3 deletions

View File

@ -16,7 +16,7 @@ export const CurrentUserProvider = (props) => {
if (result.loading) {
return <Spin />;
}
if (result.error) {
if (!result?.data?.data?.id) {
return <Redirect to={'/signin'} />;
}
return <CurrentUserContext.Provider value={result}>{props.children}</CurrentUserContext.Provider>;

View File

@ -6,10 +6,10 @@ export async function check(ctx: Context, next: Next) {
if (ctx.state.currentUser) {
const user = ctx.state.currentUser.toJSON();
ctx.body = user;
await next();
} else {
ctx.throw(401, 'Unauthorized');
ctx.body = {};
}
await next();
}
export async function signin(ctx: Context, next: Next) {