diff --git a/src/app/admin/(block)/block-menu.tsx b/src/app/admin/(block)/block-menu.tsx index cf27e64b..716786a1 100644 --- a/src/app/admin/(block)/block-menu.tsx +++ b/src/app/admin/(block)/block-menu.tsx @@ -1,5 +1,5 @@ import React, { SetStateAction } from "react"; -import { blockTypes } from "@config/block_types"; +import { blockTypes } from "@/types/block_types"; import Link from "next/link"; import Image from "next/image"; import Portal from "@app/components/portal"; diff --git a/src/app/admin/(block)/calendar/components/schedule-form.tsx b/src/app/admin/(block)/calendar/components/schedule-form.tsx index 8c4dc291..1edc64d6 100644 --- a/src/app/admin/(block)/calendar/components/schedule-form.tsx +++ b/src/app/admin/(block)/calendar/components/schedule-form.tsx @@ -74,19 +74,10 @@ export default function ScheduleForm({ if (mode === "edit") return; try { - const token = sessionStorage.getItem("token"); - if (!token) { - throw new Error("로그인이 필요합니다."); - } - - const response = await fetch( - `${process.env.NEXT_PUBLIC_API_URL}/api/link/list`, - { - headers: { - Authorization: `Bearer ${token}`, - }, - }, - ); + const response = await fetch("/api/link/list", { + credentials: "include", + method: "GET", + }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); @@ -121,17 +112,10 @@ export default function ScheduleForm({ }; try { - const token = sessionStorage.getItem("token"); - if (!token) throw new Error("인증 토큰이 없습니다. 다시 로그인해주세요."); - - const listResponse = await fetch( - `${process.env.NEXT_PUBLIC_API_URL}/api/link/list`, - { - headers: { - Authorization: `Bearer ${token}`, - }, - }, - ); + const listResponse = await fetch("/api/link/list", { + credentials: "include", + method: "GET", + }); if (!listResponse.ok) { throw new Error("기존 일정을 불러오는데 실패했습니다."); @@ -161,33 +145,23 @@ export default function ScheduleForm({ requestBody = { id: blockId, type: 7, - sequence: existingCalendarBlock?.sequence || 1, style: existingCalendarBlock?.style || 1, schedule: updatedSchedules, }; } else { // 새로운 캘린더 블록 생성 및 일정 추가 - const nextSequence = await getSequence(); - if (!nextSequence) return; requestBody = { type: 7, - sequence: nextSequence + 1, style: 1, schedule: [newSchedule], }; } - const response = await fetch( - `${process.env.NEXT_PUBLIC_API_URL}/api/link/${blockId ? "update" : "add"}`, - { - method: "POST", - headers: { - "Content-Type": "application/json", - Authorization: `Bearer ${token}`, - }, - body: JSON.stringify(requestBody), - }, - ); + const response = await fetch(`/api/link/${blockId ? "update" : "add"}`, { + credentials: "include", + method: "POST", + body: JSON.stringify(requestBody), + }); if (!response.ok) { throw new Error( diff --git a/src/app/admin/(block)/calendar/components/schedule-list.tsx b/src/app/admin/(block)/calendar/components/schedule-list.tsx index d91ce760..54469944 100644 --- a/src/app/admin/(block)/calendar/components/schedule-list.tsx +++ b/src/app/admin/(block)/calendar/components/schedule-list.tsx @@ -193,12 +193,11 @@ export default function ScheduleList() { const requestBody = { id: calendarBlock.id, type: 7, - sequence: calendarBlock.sequence, style: calendarBlock.style, schedule: updatedSchedules, }; - const response = await fetch(`$/api/link/update`, { + const response = await fetch(`/api/link/update`, { method: "POST", headers: { "Content-Type": "application/json", diff --git a/src/app/admin/(block)/calendar/manage/page.tsx b/src/app/admin/(block)/calendar/manage/page.tsx index 5f41a274..9dd01b05 100644 --- a/src/app/admin/(block)/calendar/manage/page.tsx +++ b/src/app/admin/(block)/calendar/manage/page.tsx @@ -50,17 +50,10 @@ function ScheduleContent() { } try { - const token = sessionStorage.getItem("token"); - if (!token) throw new Error("로그인이 필요합니다."); - - const response = await fetch( - `${process.env.NEXT_PUBLIC_API_URL}/api/link/list`, - { - headers: { - Authorization: `Bearer ${token}`, - }, - }, - ); + const response = await fetch("/api/link/list", { + credentials: "include", + method: "POST", + }); if (!response.ok) throw new Error("데이터를 불러오는데 실패했습니다."); diff --git a/src/app/admin/components/home-menu.tsx b/src/app/admin/components/home-menu.tsx index 33b5e1e1..09784762 100644 --- a/src/app/admin/components/home-menu.tsx +++ b/src/app/admin/components/home-menu.tsx @@ -11,6 +11,14 @@ const HomeMenu = () => { async function handleLogout() { try { // 인증 관련 데이터 제거 + const response = await fetch("/api/logout", { + credentials: "include", + method: "POST", + }); + if (response.ok) { + alert("로그아웃 되었습니다."); + router.push(`/intro`); + } } catch (error) { console.error("로그아웃 중 오류 발생:", error); } diff --git a/src/app/api/link/add/route.tsx b/src/app/api/link/add/route.tsx index 34678c5a..6519b7fe 100644 --- a/src/app/api/link/add/route.tsx +++ b/src/app/api/link/add/route.tsx @@ -18,7 +18,6 @@ interface ScheduleType { interface NewData { id: number; type: number; - sequence: number; url?: string; style?: number; title?: string; @@ -53,12 +52,11 @@ export async function POST(request: NextRequest) { ) as JwtPayload; const userId = decoded.userId; const userDocument = await collection.findOne({ userId }); - const newId = userDocument?.data.length ?? 0; + const newId = userDocument?.data?.length ?? 0; const body = await request.json(); const { type, - sequence, url, style, title, @@ -73,7 +71,6 @@ export async function POST(request: NextRequest) { const newData: NewData = { id: newId, type, - sequence, url, style, title, @@ -82,15 +79,12 @@ export async function POST(request: NextRequest) { subText02, dateStart, dateEnd, - schedule, + schedule: schedule?.map((item: ScheduleType, index: number) => ({ + ...item, + id: index, + })), }; - await collection.updateOne( - { userId }, - { $setOnInsert: { data: [] } }, - { upsert: true }, - ); - const result = await collection.updateOne( { userId }, { $push: { data: newData } }, diff --git a/src/app/api/link/update/route.tsx b/src/app/api/link/update/route.tsx index 7bd9b7d2..4200e6b0 100644 --- a/src/app/api/link/update/route.tsx +++ b/src/app/api/link/update/route.tsx @@ -13,7 +13,7 @@ interface UserDocument { } interface ScheduleType { - id: number; + id?: number; title: string; url: string; dateStart: string; diff --git a/src/app/api/logout/route.tsx b/src/app/api/logout/route.tsx index f07fb520..52f8662f 100644 --- a/src/app/api/logout/route.tsx +++ b/src/app/api/logout/route.tsx @@ -1,6 +1,6 @@ import { NextResponse } from "next/server"; -export async function GET() { +export async function POST() { try { const response = NextResponse.json({ message: "Logged out successfully" }); diff --git a/src/app/profile/edit/page.tsx b/src/app/profile/edit/page.tsx index 48568c1d..7180a00c 100644 --- a/src/app/profile/edit/page.tsx +++ b/src/app/profile/edit/page.tsx @@ -78,7 +78,7 @@ export default function ProfileEdit() { useEffect(() => { async function fetchUserInfo() { try { - const response = await fetch(`$/api/user/info`, { + const response = await fetch(`/api/user/info`, { credentials: "include", }); const data = await response.json(); diff --git a/src/middleware.ts b/src/middleware.ts index 40e42cf7..45bf5bda 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -2,7 +2,7 @@ import { NextRequest, NextResponse } from "next/server"; export function middleware(request: NextRequest) { - const token = request.cookies.get("token"); + // const token = request.cookies.get("token"); // 비로그인 사용자가 특정 페이지에 접근하면 intro 페이지로 리다이렉트 // if ( diff --git a/src/config/block_types.ts b/src/types/block_types.ts similarity index 100% rename from src/config/block_types.ts rename to src/types/block_types.ts diff --git a/src/utils/apis/index.ts b/src/utils/apis/index.ts index 98e630ff..c0205c9c 100644 --- a/src/utils/apis/index.ts +++ b/src/utils/apis/index.ts @@ -8,8 +8,6 @@ class Apis { } class adminApis extends Apis { - sequence: number | undefined = undefined; - async getVisitor() { try { return await fetch(`/api/user/visitor`, { @@ -33,7 +31,6 @@ class adminApis extends Apis { }); if (response.ok) { - this.sequence = 0; return response; } else { return response;