fix(fe/state_updater): captcha is not loaded if the token is expired

This commit is contained in:
hexxa 2022-02-25 15:35:23 +08:00 committed by Hexxa
parent 0967ca53dc
commit 4896fd47fc
2 changed files with 15 additions and 20 deletions

View file

@ -123,9 +123,7 @@ describe("State Manager", () => {
expect(coreState.msg.pkg).toEqual(MsgPackage.get("en_US"));
// ui
expect(coreState.ui.bg).toEqual(
settingsResps.getClientCfgMockResp.data.bg
);
expect(coreState.ui.bg).toEqual(settingsResps.getClientCfgMockResp.data.bg);
});
test("initUpdater for visitor in sharing mode", async () => {
@ -225,9 +223,7 @@ describe("State Manager", () => {
expect(coreState.msg.pkg).toEqual(MsgPackage.get("en_US"));
// ui
expect(coreState.ui.bg).toEqual(
settingsResps.getClientCfgMockResp.data.bg
);
expect(coreState.ui.bg).toEqual(settingsResps.getClientCfgMockResp.data.bg);
});
test("initUpdater for visitor", async () => {
@ -251,9 +247,9 @@ describe("State Manager", () => {
);
usersCl.getCaptchaID = jest.fn().mockReturnValue(
makePromise({
status: 400,
status: 200,
statusText: "",
data: { error: "empty captcha ID" },
data: { id: "357124" },
})
);
@ -292,7 +288,7 @@ describe("State Manager", () => {
usedSpace: "0",
},
authed: false,
captchaID: "",
captchaID: "357124",
preferences: {
bg: {
url: "",
@ -319,10 +315,10 @@ describe("State Manager", () => {
// ui
expect(coreState.ui.bg).toEqual({
url: "",
repeat: "",
position: "",
align: "",
align: "clientCfg_bg_align",
position: "clientCfg_bg_position",
repeat: "clientCfg_bg_repeat",
url: "clientCfg_bg_url",
});
});
});

View file

@ -520,6 +520,11 @@ export class Updater {
};
initAuth = async (): Promise<string> => {
const getCapStatus = await this.getCaptchaID();
if (getCapStatus !== "") {
return getCapStatus;
}
const isAuthedStatus = await this.syncIsAuthed();
if (isAuthedStatus !== "") {
return isAuthedStatus;
@ -530,11 +535,6 @@ export class Updater {
return selfStatuses;
}
const getCapStatus = await this.getCaptchaID();
if (getCapStatus !== "") {
return getCapStatus;
}
return "";
};
@ -600,7 +600,6 @@ export class Updater {
spaceLimit: "0",
};
this.props.login.authed = false;
this.props.login.captchaID = "";
this.props.login.preferences = {
bg: {
url: "",
@ -732,7 +731,7 @@ export class Updater {
syncIsAuthed = async (): Promise<string> => {
const resp = await this.usersClient.isAuthed();
if (resp.status !== 200) {
this.props.login.authed = false;
this.resetUser();
return resp.status === 401 ? "" : errServer;
}
this.props.login.authed = true;