261102_02_ENH: 공용 인증 쿠키 도메인 적용 조건 수정 및 외부 링크 인증 탭별 분리
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { reportUrl } from "@/types/share";
|
||||
import { readExternalAuth } from "@/lib/external-auth";
|
||||
|
||||
// Set false to disable only cross-tab notifications and their listener.
|
||||
const AUTH_CHANGE_SYNC_ENABLED = true;
|
||||
const CHANNEL = "kart:auth-change";
|
||||
const CHANNEL = "kart:internal-auth-change";
|
||||
let channel: BroadcastChannel | undefined;
|
||||
|
||||
function authChannel() {
|
||||
@@ -15,7 +15,7 @@ function authChannel() {
|
||||
}
|
||||
}
|
||||
|
||||
export function notifyAuthChange(path: string) {
|
||||
export function notifyAuthChange(path: "/" | "/login") {
|
||||
authChannel()?.postMessage(path);
|
||||
}
|
||||
|
||||
@@ -23,10 +23,11 @@ export function subscribeToAuthChanges() {
|
||||
const listener = authChannel();
|
||||
if (!listener) return;
|
||||
listener.onmessage = (event: MessageEvent<unknown>) => {
|
||||
const path = event.data === "/" || event.data === "/login"
|
||||
? event.data : reportUrl(event.data);
|
||||
// A normal-login change must not navigate an independently authenticated link tab.
|
||||
if (readExternalAuth()) return;
|
||||
if (event.data !== "/" && event.data !== "/login") return;
|
||||
// A full navigation discards this tab's cache/state without clearing the new cookie.
|
||||
if (path) window.location.replace(path);
|
||||
window.location.replace(event.data);
|
||||
};
|
||||
return () => {
|
||||
listener.close();
|
||||
|
||||
Reference in New Issue
Block a user