🐛 fix: enhance logout functionality to support hash-based routing and improve redirect logic
This commit is contained in:
parent
56051b86bb
commit
69a89e0c39
@ -59,9 +59,18 @@ export function setRedirectUrl(value?: string) {
|
|||||||
export function Logout() {
|
export function Logout() {
|
||||||
if (!isBrowser()) return;
|
if (!isBrowser()) return;
|
||||||
removeCookie("Authorization");
|
removeCookie("Authorization");
|
||||||
|
|
||||||
const pathname = location.pathname;
|
const pathname = location.pathname;
|
||||||
|
const hash = location.hash.slice(1);
|
||||||
|
|
||||||
if (!["", "/"].includes(pathname)) {
|
if (!["", "/"].includes(pathname)) {
|
||||||
setRedirectUrl(location.pathname);
|
setRedirectUrl(pathname);
|
||||||
|
location.href = "/";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hash && !["", "/"].includes(hash)) {
|
||||||
|
setRedirectUrl(hash);
|
||||||
location.href = "/";
|
location.href = "/";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -46,7 +46,10 @@ export function setRedirectUrl(value?: string) {
|
|||||||
export function Logout() {
|
export function Logout() {
|
||||||
if (!isBrowser()) return;
|
if (!isBrowser()) return;
|
||||||
removeCookie("Authorization");
|
removeCookie("Authorization");
|
||||||
|
|
||||||
const pathname = location.pathname;
|
const pathname = location.pathname;
|
||||||
|
const hash = location.hash.slice(1); // 移除 '#'
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!(
|
!(
|
||||||
["", "/", "/auth", "/tos", "/privacy-policy"].includes(pathname) ||
|
["", "/", "/auth", "/tos", "/privacy-policy"].includes(pathname) ||
|
||||||
@ -54,7 +57,20 @@ export function Logout() {
|
|||||||
pathname.startsWith("/oauth/")
|
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";
|
location.href = "/#/auth";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user