43 lines
1,023 B
JavaScript
43 lines
1,023 B
JavaScript
|
|
/**
|
||
|
|
* 어드민 인증 API
|
||
|
|
*/
|
||
|
|
import { fetchAdminApi } from "../index";
|
||
|
|
|
||
|
|
// 토큰 검증
|
||
|
|
export async function verifyToken() {
|
||
|
|
return fetchAdminApi("/api/admin/verify");
|
||
|
|
}
|
||
|
|
|
||
|
|
// 로그인
|
||
|
|
export async function login(username, password) {
|
||
|
|
const response = await fetch("/api/admin/login", {
|
||
|
|
method: "POST",
|
||
|
|
headers: { "Content-Type": "application/json" },
|
||
|
|
body: JSON.stringify({ username, password }),
|
||
|
|
});
|
||
|
|
|
||
|
|
if (!response.ok) {
|
||
|
|
const error = await response.json();
|
||
|
|
throw new Error(error.error || "로그인 실패");
|
||
|
|
}
|
||
|
|
|
||
|
|
return response.json();
|
||
|
|
}
|
||
|
|
|
||
|
|
// 로그아웃 (로컬 스토리지 정리)
|
||
|
|
export function logout() {
|
||
|
|
localStorage.removeItem("adminToken");
|
||
|
|
localStorage.removeItem("adminUser");
|
||
|
|
}
|
||
|
|
|
||
|
|
// 현재 사용자 정보 가져오기
|
||
|
|
export function getCurrentUser() {
|
||
|
|
const userData = localStorage.getItem("adminUser");
|
||
|
|
return userData ? JSON.parse(userData) : null;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 토큰 존재 여부 확인
|
||
|
|
export function hasToken() {
|
||
|
|
return !!localStorage.getItem("adminToken");
|
||
|
|
}
|