支持钉钉刷新时同步用户信息
This commit is contained in:
parent
1d39ff253a
commit
225f8f758e
18
src/App.vue
18
src/App.vue
@ -2,6 +2,7 @@
|
|||||||
import { onMounted, onUnmounted } from "vue";
|
import { onMounted, onUnmounted } from "vue";
|
||||||
import { RouterView } from "vue-router";
|
import { RouterView } from "vue-router";
|
||||||
|
|
||||||
|
import { isDingTalkContainer } from "@/api/dingtalk";
|
||||||
import router from "@/router";
|
import router from "@/router";
|
||||||
import { useAuthStore } from "@/stores/auth.store";
|
import { useAuthStore } from "@/stores/auth.store";
|
||||||
|
|
||||||
@ -17,9 +18,20 @@ function handleAuthExpired() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() =>
|
onMounted(() => {
|
||||||
window.addEventListener("risk-auth-expired", handleAuthExpired),
|
window.addEventListener("risk-auth-expired", handleAuthExpired);
|
||||||
);
|
// A persisted JWT only refreshes /auth/me and cannot update stale DingTalk
|
||||||
|
// department/name fields. Re-sync the organization identity once per page
|
||||||
|
// load when the app is opened inside DingTalk, without logging out on error.
|
||||||
|
if (
|
||||||
|
isDingTalkContainer() &&
|
||||||
|
auth.token &&
|
||||||
|
auth.user?.dingtalkId &&
|
||||||
|
!auth.user.dingtalkId.startsWith("local-")
|
||||||
|
) {
|
||||||
|
void auth.dingTalkLogin(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
onUnmounted(() =>
|
onUnmounted(() =>
|
||||||
window.removeEventListener("risk-auth-expired", handleAuthExpired),
|
window.removeEventListener("risk-auth-expired", handleAuthExpired),
|
||||||
);
|
);
|
||||||
|
|||||||
@ -61,7 +61,7 @@ export const useAuthStore = defineStore("auth", () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function dingTalkLogin() {
|
async function dingTalkLogin(preserveSessionOnFailure = false) {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
error.value = null;
|
error.value = null;
|
||||||
try {
|
try {
|
||||||
@ -69,7 +69,7 @@ export const useAuthStore = defineStore("auth", () => {
|
|||||||
saveToken(response.accessToken);
|
saveToken(response.accessToken);
|
||||||
user.value = response.user;
|
user.value = response.user;
|
||||||
} catch (reason) {
|
} catch (reason) {
|
||||||
clear();
|
if (!preserveSessionOnFailure) clear();
|
||||||
error.value = reason instanceof Error ? reason.message : "钉钉免登失败";
|
error.value = reason instanceof Error ? reason.message : "钉钉免登失败";
|
||||||
throw reason;
|
throw reason;
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user