Skip to content

Commit

Permalink
Logout after changing user information
Browse files Browse the repository at this point in the history
  • Loading branch information
Integral-Tech committed Nov 14, 2023
1 parent 75ca0b8 commit c7ea6cd
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/components/UserInfo/Basic.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import { reactive } from "vue";
import { useLoginStore } from "../../store/loginStore";
import { useI18n } from "vue-i18n";
import { throwError } from "../Error";
import { logout } from "./common";
import axios from "axios";
import router from "../../router";
const loginStore = useLoginStore();
const { t } = useI18n();
Expand Down Expand Up @@ -69,7 +69,7 @@ function saveUserInfo(): void {
})
.then(() => {
ElMessage.success(t("userInfo.basic.successPrompt"));
router.push("/");
logout();
})
.catch((error) => {
throwError(error, "userInfo.basic.errPrompt", t);
Expand Down
4 changes: 2 additions & 2 deletions src/components/UserInfo/ChangeAvatar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import { VueCropper } from "vue-cropper";
import { useLoginStore } from "../../store/loginStore";
import { useI18n } from "vue-i18n";
import { throwError } from "../Error";
import { logout } from "./common";
import axios from "axios";
import router from "../../router";
import "vue-cropper/dist/index.css";
const loginStore = useLoginStore();
Expand Down Expand Up @@ -89,7 +89,7 @@ function saveAvatar(): void {
)
.then(() => {
ElMessage.success(t("userInfo.avatar.successPrompt"));
router.push("/");
logout();
})
.catch((error) => {
throwError(error, "userInfo.avatar.errPrompt", t);
Expand Down
4 changes: 2 additions & 2 deletions src/components/UserInfo/ChangePwd.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ import { reactive } from "vue";
import { useI18n } from "vue-i18n";
import { useLoginStore } from "../../store/loginStore";
import { throwError } from "../Error";
import { logout } from "./common";
import sha3 from "crypto-js/sha3";
import axios from "axios";
import router from "../../router";
const form = reactive({
originalPwd: "",
Expand Down Expand Up @@ -86,7 +86,7 @@ function savePasswd(): void {
})
.then(() => {
ElMessage.success(t("userinfo.changePwd.successPrompt"));
router.push("/");
logout();
})
.catch((error) => {
throwError(error, "userinfo.changePwd.errorPrompt", t);
Expand Down
4 changes: 2 additions & 2 deletions src/components/UserInfo/DeleteUser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ import { reactive } from "vue";
import { useLoginStore } from "../../store/loginStore";
import { useI18n } from "vue-i18n";
import { throwError } from "../Error";
import { logout } from "./common";
import axios from "axios";
import sha3 from "crypto-js/sha3";
import router from "../../router";
const form = reactive({
passwd1: "",
Expand Down Expand Up @@ -75,7 +75,7 @@ function deleteUser(): void {
.delete(`/api/users/${loginStore.userVo?.id}`)
.then(() => {
ElMessage.success(t("userInfo.delete.successPrompt"));
router.push("/");
logout();
})
.catch((error) => {
throwError(error, "userInfo.delete.errPrompt", t);
Expand Down
12 changes: 12 additions & 0 deletions src/components/UserInfo/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { useLoginStore } from "../../store/loginStore";
import router from "../../router";

const loginStore = useLoginStore();

export function logout(): void {
loginStore.userVo = null;
loginStore.password = "";
loginStore.avatar = "";
localStorage.removeItem("satoken");
router.push("/");
}

0 comments on commit c7ea6cd

Please sign in to comment.