Skip to content

Commit 5a3c215

Browse files
authored
Merge pull request #151 from hhjin1/card-hj
[Feat] 카드 생성 후 새로고침 기능 추가
2 parents e9c2b09 + e898639 commit 5a3c215

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/api/axiosInstance.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1+
// axiosInstance.ts
2+
13
import axios from "axios";
24

35
const axiosInstance = axios.create({
46
baseURL: "https://sp-taskify-api.vercel.app",
57
});
68

9+
// 👉 Authorization 헤더 자동 설정, 요청 보낼때 마다 localstorage에서 토큰 가져오기
10+
axiosInstance.interceptors.request.use((config) => {
11+
const token = localStorage.getItem("accessToken"); // localStorage에서 토큰 가져오기
12+
if (token) {
13+
config.headers.Authorization = `Bearer ${token}`; // 헤더에 Authorization 추가
14+
}
15+
return config;
16+
});
17+
718
// 👉 요청 보낼 때마다 토큰 자동 추가
819
axiosInstance.interceptors.request.use((config) => {
920
const token = localStorage.getItem("accessToken"); // localStorage에서 토큰 가져오기

src/components/modalInput/ToDoModal.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import ModalInput from "@/components/modalInput/ModalInput";
55
import ModalTextarea from "@/components/modalInput/ModalTextarea";
66
import ModalImage from "@/components/modalInput/ModalImage";
77
import TextButton from "@/components/modalInput/TextButton";
8+
import { useRouter } from "next/router";
89

910
interface TaskModalProps {
1011
isOpen: boolean;
@@ -42,6 +43,8 @@ export default function TaskModal({
4243
image: "",
4344
});
4445

46+
const router = useRouter();
47+
4548
const handleChange = (field: keyof TaskData, value: string | string[]) => {
4649
setFormData((prev) => ({
4750
...prev,
@@ -78,6 +81,7 @@ export default function TaskModal({
7881
imageUrl: formData.image || undefined,
7982
});
8083

84+
router.reload(); // 카드 생성 후 새로고침
8185
onClose();
8286
} catch (err) {
8387
console.error("카드 생성 실패:", err);

0 commit comments

Comments
 (0)