[cs] feat: auth service 수정 (BaseLayout DI 패턴)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
ACCESS_TOKEN,
|
||||
AUTH_LOGIN_REDIRECT_URL,
|
||||
AUTH_USER_ID,
|
||||
CLAIM_NAME,
|
||||
ENDPOINT,
|
||||
@@ -8,6 +9,7 @@ import { getRemainingMs } from "@common/auth";
|
||||
|
||||
import {
|
||||
clearAuthToken,
|
||||
removeToken,
|
||||
setToken,
|
||||
setupRefreshTimer,
|
||||
} from "../lib/token-manager";
|
||||
@@ -99,9 +101,22 @@ async function silentRefresh(): Promise<void> {
|
||||
}
|
||||
|
||||
async function logout(): Promise<void> {
|
||||
try {
|
||||
await fetch("/api/auth/logout", {
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Logout API failed:", error);
|
||||
}
|
||||
|
||||
clearAuthToken();
|
||||
removeToken("site-id-key");
|
||||
removeToken("site-theme-key");
|
||||
|
||||
if (typeof window !== "undefined") {
|
||||
window.dispatchEvent(new CustomEvent("auth:logout"));
|
||||
window.location.href = AUTH_LOGIN_REDIRECT_URL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1 @@
|
||||
export interface AuthPayload {
|
||||
userId: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
export interface AuthService {
|
||||
login(payload: AuthPayload): Promise<void>;
|
||||
silentRefresh(): Promise<void>;
|
||||
logout(): Promise<void>;
|
||||
}
|
||||
export type { AuthPayload, AuthService } from "@common/auth";
|
||||
|
||||
Reference in New Issue
Block a user