Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app/admin/(block)/block-menu.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
52 changes: 13 additions & 39 deletions src/app/admin/(block)/calendar/components/schedule-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down Expand Up @@ -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("๊ธฐ์กด ์ผ์ •์„ ๋ถˆ๋Ÿฌ์˜ค๋Š”๋ฐ ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.");
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 1 addition & 2 deletions src/app/admin/(block)/calendar/components/schedule-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 4 additions & 11 deletions src/app/admin/(block)/calendar/manage/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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("๋ฐ์ดํ„ฐ๋ฅผ ๋ถˆ๋Ÿฌ์˜ค๋Š”๋ฐ ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.");
Expand Down
8 changes: 8 additions & 0 deletions src/app/admin/components/home-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
16 changes: 5 additions & 11 deletions src/app/api/link/add/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ interface ScheduleType {
interface NewData {
id: number;
type: number;
sequence: number;
url?: string;
style?: number;
title?: string;
Expand Down Expand Up @@ -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,
Expand All @@ -73,7 +71,6 @@ export async function POST(request: NextRequest) {
const newData: NewData = {
id: newId,
type,
sequence,
url,
style,
title,
Expand All @@ -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 } },
Expand Down
2 changes: 1 addition & 1 deletion src/app/api/link/update/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface UserDocument {
}

interface ScheduleType {
id: number;
id?: number;
title: string;
url: string;
dateStart: string;
Expand Down
2 changes: 1 addition & 1 deletion src/app/api/logout/route.tsx
Original file line number Diff line number Diff line change
@@ -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" });

Expand Down
2 changes: 1 addition & 1 deletion src/app/profile/edit/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
File renamed without changes.
3 changes: 0 additions & 3 deletions src/utils/apis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ class Apis {
}

class adminApis extends Apis {
sequence: number | undefined = undefined;

async getVisitor() {
try {
return await fetch(`/api/user/visitor`, {
Expand All @@ -33,7 +31,6 @@ class adminApis extends Apis {
});

if (response.ok) {
this.sequence = 0;
return response;
} else {
return response;
Expand Down