알림 시간봉 오류 수정

This commit is contained in:
Macbook
2026-05-29 20:42:35 +09:00
parent a5f0a7eefd
commit 775f83e1b3
13 changed files with 200 additions and 35 deletions
@@ -0,0 +1,38 @@
/**
* STOMP·실시간 시그널 소유자 검증 — 로그인 사용자는 user_id, 비로그인은 device_id 기준.
*/
export interface SignalOwnership {
userId?: number | null;
deviceId?: string | null;
}
function readDeviceId(): string {
return localStorage.getItem('gc_device_id') ?? '';
}
function readUserId(): number | null {
const raw = localStorage.getItem('gc_user_id');
if (!raw) return null;
const id = Number(raw);
return Number.isFinite(id) && id > 0 ? id : null;
}
export function getCurrentSignalSession(): { userId: number | null; deviceId: string } {
return { userId: readUserId(), deviceId: readDeviceId() };
}
/** STOMP 페이로드·DB 시그널이 현재 세션 소유인지 */
export function signalBelongsToCurrentSession(owner: SignalOwnership): boolean {
const { userId, deviceId } = getCurrentSignalSession();
if (owner.userId != null && owner.userId > 0) {
return userId != null && userId === owner.userId;
}
if (owner.deviceId != null && owner.deviceId !== '') {
return userId == null && owner.deviceId === deviceId;
}
// 소유자 메타 없음(레거시 브로드캐스트) — 타 사용자 시그널 유입 방지
return false;
}