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

View file

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