Fix SilentSignin logic

This commit is contained in:
Gucheng Wang 2022-09-30 01:49:43 +08:00
parent 62b058eb5e
commit ef70126b37
2 changed files with 16 additions and 6 deletions

View File

@ -78,7 +78,7 @@ export function getMyResourcesUrl(account) {
export function signin() {
return CasdoorSdk.signin(ServerUrl).then((res) => {
if (res.status === "ok") {
if (window !== window.parent) {
if (inIframe()) {
const message = {tag: "Casdoor", type: "SilentSignin", data: "success"};
window.parent.postMessage(message, "*");
}
@ -89,6 +89,14 @@ export function signin() {
});
}
export function inIframe() {
try {
return window !== window.parent;
} catch (e) {
return true;
}
}
export function scrollToTop() {
scroll.scrollToTop();
}

View File

@ -33,17 +33,19 @@ class SilentSignin extends React.Component {
return;
}
if (message.type === "SilentSignin" && message.data === "success") {
Setting.showMessageEx("success", i18next.t("login:Logged in successfully"), 1, () => Setting.goToLink("/"));
} else if (message.type === "SilentSignin" && message.data === "user-not-logged-in") {
Setting.showMessageEx("error", i18next.t("login:Failed to log in"), 1, () => Setting.goToLink("/"));
if (message.type === "SilentSignin") {
if (message.data === "success") {
Setting.showMessageEx("success", i18next.t("login:Logged in successfully"), 1, () => Setting.goToLink("/"));
} else if (message.data === "user-not-logged-in") {
// Setting.showMessageEx("error", i18next.t("login:Failed to log in"), 1, () => Setting.goToLink("/"));
}
}
});
}
render() {
// don't silent-sign-in recursively in iframe
if (window !== window.parent) {
if (Setting.inIframe()) {
return null;
}