Skip to content

Commit

Permalink
perf: auto loggout when password was changed
Browse files Browse the repository at this point in the history
  • Loading branch information
wibus-wee committed May 1, 2023
1 parent 57ebe9e commit fbbf49d
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/pages/Settings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ import { Toggle } from "@components/universal/Toggle";
import { jump } from "@utils/path";
import { useSeo } from "@hooks/useSeo";
import { toast } from "sonner";
import useSWR from "swr";
import useSWR, { mutate } from "swr";
import { Space } from "@components/universal/Space";
import { app } from "@states/app";
import { removeCookie } from "@utils/cookie";

const tabsAPI = ["/user/master/info", "/configs"];

Expand Down Expand Up @@ -125,7 +127,7 @@ export const SettingsPage: BasicPage = () => {
}}
/>
<Input
value={_user?.password || ""}
value={_user?.password}
type="password"
style={{
backgroundColor: "var(--background-color-primary)",
Expand All @@ -151,6 +153,13 @@ export const SettingsPage: BasicPage = () => {
error: "保存失败",
}
);
if (_user.password) {
removeCookie("token");
app.authenticated = false;
navigate(jump("/login"));
mutate("/user/check");
toast("您修改了密码,请重新登录");
}
}}
>
保存
Expand Down Expand Up @@ -359,7 +368,7 @@ function handleExportData() {
a.click();
URL.revokeObjectURL(url);
return res;
})
});
toast.promise(handler, {
loading: "正在导出",
success: "导出成功",
Expand Down Expand Up @@ -390,6 +399,6 @@ function handleImportData() {
});
};
reader.readAsText(file);
}
};
input.click();
}
}

0 comments on commit fbbf49d

Please sign in to comment.