🐛 fix: enhance logout functionality to support hash-based routing and improve redirect logic

This commit is contained in:
web 2025-12-16 06:25:38 -08:00
parent 56051b86bb
commit 69a89e0c39
2 changed files with 27 additions and 2 deletions

View File

@ -59,9 +59,18 @@ export function setRedirectUrl(value?: string) {
export function Logout() {
if (!isBrowser()) return;
removeCookie("Authorization");
const pathname = location.pathname;
const hash = location.hash.slice(1);
if (!["", "/"].includes(pathname)) {
setRedirectUrl(location.pathname);
setRedirectUrl(pathname);
location.href = "/";
return;
}
if (hash && !["", "/"].includes(hash)) {
setRedirectUrl(hash);
location.href = "/";
}
}

View File

@ -46,7 +46,10 @@ export function setRedirectUrl(value?: string) {
export function Logout() {
if (!isBrowser()) return;
removeCookie("Authorization");
const pathname = location.pathname;
const hash = location.hash.slice(1); // 移除 '#'
if (
!(
["", "/", "/auth", "/tos", "/privacy-policy"].includes(pathname) ||
@ -54,7 +57,20 @@ export function Logout() {
pathname.startsWith("/oauth/")
)
) {
setRedirectUrl(location.pathname);
setRedirectUrl(pathname);
location.href = "/#/auth";
return;
}
if (
hash &&
!(
["", "/", "/auth", "/tos", "/privacy-policy"].includes(hash) ||
hash.startsWith("/purchasing") ||
hash.startsWith("/oauth/")
)
) {
setRedirectUrl(hash);
location.href = "/#/auth";
}
}