Handle Auth redirect in MailboxDashboardController
Signed-off-by: dab246 <tdvu@linagora.com>
This commit is contained in:
+31
-24
@@ -1,31 +1,38 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<html lang="en">
|
||||
<head>
|
||||
<script>
|
||||
const AUTH_DESTINATION_KEY = "auth_destination_url";
|
||||
const AUTH_RESPONSE_KEY = "auth_info";
|
||||
<script>
|
||||
const AUTH_DESTINATION_KEY = "auth_destination_url";
|
||||
const AUTH_RESPONSE_KEY = "auth_info";
|
||||
|
||||
window.onload = function () {
|
||||
if (window.opener && window.opener !== window) { //Used when working as a popup. Uses post message to respond to the parent window
|
||||
var parent = window.opener ?? window.parent;
|
||||
parent.postMessage(location.href, "*");
|
||||
} else { //Used for redirect loop functionality.
|
||||
//Get the original page destination
|
||||
const destination = sessionStorage.getItem(AUTH_DESTINATION_KEY || "/");
|
||||
sessionStorage.removeItem(AUTH_DESTINATION_KEY);
|
||||
//Store the current window location that will be used to get the information for authentication
|
||||
sessionStorage.setItem(AUTH_RESPONSE_KEY, window.location);
|
||||
window.onload = function () {
|
||||
try {
|
||||
// Get the original page destination
|
||||
const destination = sessionStorage.getItem(AUTH_DESTINATION_KEY) || "/";
|
||||
sessionStorage.removeItem(AUTH_DESTINATION_KEY);
|
||||
|
||||
//Redirect to where we're going so that we can restore state completely
|
||||
location.assign(destination);
|
||||
}
|
||||
// Store the current window location that will be used to get the information for authentication
|
||||
sessionStorage.setItem(AUTH_RESPONSE_KEY, window.location);
|
||||
|
||||
// Build the redirect URL
|
||||
let redirectUrl;
|
||||
if (destination.includes("/login")) {
|
||||
redirectUrl = destination.replace("/login", "/dashboard?type=normal");
|
||||
} else {
|
||||
const separator = destination.endsWith("/") ? "" : "/";
|
||||
redirectUrl = destination + separator + "dashboard?type=normal";
|
||||
}
|
||||
</script>
|
||||
|
||||
// Perform redirection
|
||||
location.assign(redirectUrl);
|
||||
} catch (error) {
|
||||
console.error("[Auth Redirect] Redirection failed:", error);
|
||||
location.assign("/");
|
||||
}
|
||||
};
|
||||
</script>
|
||||
<title>Twake Mail</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
<body></body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user