Skip to content

Commit

Permalink
Merge pull request #140 from JNU-econovation/feat/133/add-token-to-he…
Browse files Browse the repository at this point in the history
…ader

feat: add token to header
  • Loading branch information
kanghaeun authored Jul 23, 2024
2 parents dfee98c + d7629ad commit c698f03
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 49 deletions.
8 changes: 7 additions & 1 deletion FE/error/src/components/DeleteEvent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ const DeleteEvent = ({
onRequestClose,
handleUpdateDeleteData,
}) => {
const storedToken = localStorage.getItem("slackToken");

const calendarDelete = () => {
axios
.delete("/api/calendar/" + selectID)
.delete(`/api/calendar/${selectID}`, {
headers: {
Authorization: `Bearer ${storedToken}`,
},
})
.then(() => {
handleUpdateDeleteData(selectID);
handleDelete();
Expand Down
18 changes: 8 additions & 10 deletions FE/error/src/components/EconoCalendar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ const EconoCalendar = ({ isLoggedIn, setIsLoggedIn }) => {
const [checkModalIsOpen, setCheckModalIsOpen] = useState(false);
const [createModalIsOpen, setCreateModalIsOpen] = useState(false);
const [selectedDate, setSelectedDate] = useState("");
const [token, setToken] = useState(null);

useEffect(() => {
const storedToken = localStorage.getItem("slackToken");
setToken(storedToken);

const isUserLoggedIn = !!storedToken;
setIsLoggedIn(isUserLoggedIn);
Expand Down Expand Up @@ -89,16 +87,16 @@ const EconoCalendar = ({ isLoggedIn, setIsLoggedIn }) => {
localStorage.removeItem("slackToken");
setIsLoggedIn(false);
setToken(null);
// } else {
// const newToken = "dummyToken" + Math.random().toString(36).substr(2, 9); // 임의의 토큰 생성
// localStorage.setItem("slackToken", newToken);
// setToken(newToken);
// setIsLoggedIn(true);
// }
//TODO: 추후 아래 코드로 변경
} else {
window.location.href = "/login";
const newToken = "dummyToken" + Math.random().toString(36).substr(2, 9); // 임의의 토큰 생성
localStorage.setItem("slackToken", newToken);
setToken(newToken);
setIsLoggedIn(true);
}
//TODO: 추후 아래 코드로 변경
// } else {
// window.location.href = "/login";
// }
};

return (
Expand Down
27 changes: 16 additions & 11 deletions FE/error/src/components/scheduleCheck/CheckCalendar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const CheckCalendar = ({
handleUpdateDeleteData,
}) => {
const [event, setEvent] = useState({});
const storedToken = localStorage.getItem("slackToken");

function createDate(title, startDate, endDate, place, info, type, color) {
const specificEvent = {
Expand All @@ -42,17 +43,21 @@ const CheckCalendar = ({
return;
}

axios.get("/api/calendar/" + selectID).then((res) => {
createDate(
res.data.data.eventName,
res.data.data.eventStartDate,
res.data.data.eventEndDate,
res.data.data.eventPlace,
res.data.data.eventInfo,
res.data.data.eventType,
res.data.data.filterColor
);
});
axios
.get("/api/calendar/" + selectID, {
headers: { Authorization: `Bearer ${storedToken}` },
})
.then((res) => {
createDate(
res.data.data.eventName,
res.data.data.eventStartDate,
res.data.data.eventEndDate,
res.data.data.eventPlace,
res.data.data.eventInfo,
res.data.data.eventType,
res.data.data.filterColor
);
});
}, [selectID]);

function date(startDate, endDate) {
Expand Down
27 changes: 18 additions & 9 deletions FE/error/src/components/scheduleCreate/CreateModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const CreateModal = ({
const [eventEndTime, setEventEndTime] = useState("00:00");
const [selectedFilter, setSelectedFilter] = useState(null);
const [activeDropdown, setActiveDropdown] = useState(null);
const storedToken = localStorage.getItem("slackToken");

useEffect(() => {
if (isOpen && selectedDate) {
Expand Down Expand Up @@ -160,15 +161,23 @@ const CreateModal = ({
},
};

axios.post("/api/calendar", data).then((res) => {
createDate(
eventName,
res.data.data.eventId,
eventStartDate,
eventEndDate
);
onRequestClose();
});
axios
.post(
"/api/calendar",
{
headers: { Authorization: `Bearer ${storedToken}` },
},
data
)
.then((res) => {
createDate(
eventName,
res.data.data.eventId,
eventStartDate,
eventEndDate
);
onRequestClose();
});
};

return (
Expand Down
9 changes: 8 additions & 1 deletion FE/error/src/pages/CalendarModify.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const CalendarModify = () => {
const navigate = useNavigate();
const location = useLocation();
const selectID = location.state.selectID;
const storedToken = localStorage.getItem("slackToken");

const [modifyName, setModifyName] = useState("");
const [modifyStartDate, setModifyStartDate] = useState("");
Expand Down Expand Up @@ -75,7 +76,13 @@ const CalendarModify = () => {
eventPlace: modifyPlace,
};
axios
.put("/api/calendar/" + selectID, eventData)
.put(
"/api/calendar/" + selectID,
{
headers: { Authorization: `Bearer ${storedToken}` },
},
eventData
)
.then((res) => {
goBack();
})
Expand Down
7 changes: 5 additions & 2 deletions FE/error/src/pages/MainPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const MainPage = () => {
const [filterIndividualLists, setFilterIndividualLists] = useState([]);
const [filterGroupLists, setFilterGroupLists] = useState([]);
const [isLoggedIn, setIsLoggedIn] = useState(false);

useEffect(() => {
const token = localStorage.getItem("slackToken");
setIsLoggedIn(!!token);
Expand All @@ -29,11 +28,15 @@ const MainPage = () => {
filterIndividualLists.filter((filter) => filter.filterId !== newFilter)
);
};
const storedToken = localStorage.getItem("slackToken");

useEffect(() => {
axios
.get("/api/filter")
.get("/api/filter", {
headers: { Authorization: `Bearer ${storedToken}` },
})
.then((res) => {
console.log(res);
const fetchedFilter = res.data.data.map((filter) => ({
filterId: filter.filterId,
filterName: filter.filterName,
Expand Down
5 changes: 4 additions & 1 deletion FE/error/src/pages/ProfilePage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ const ProfilePage = () => {
const [selectedImage, setSelectedImage] = useState(null);
const [images, setImages] = useState([]);
const [isLoading, setIsLoading] = useState(true);
const storedToken = localStorage.getItem("slackToken");

useEffect(() => {
const fetchImages = async () => {
try {
const response = await axios.get("http://localhost:8080/api/images");
const response = await axios.get("http://localhost:8080/api/images", {
headers: { Authorization: `Bearer ${storedToken}` },
});
setImages(response.data);
setIsLoading(false);
} catch (error) {
Expand Down
19 changes: 12 additions & 7 deletions FE/error/src/utils/filterUtils/FilterCreateModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const FilterCreateModal = ({
}) => {
const [filterTitle, setFilterTitle] = useState("");
const [filterColor, setFilterColor] = useState("");

const storedToken = localStorage.getItem("slackToken");
const handleTitleChange = (event) => {
setFilterTitle(event.target.value);
};
Expand All @@ -24,12 +24,17 @@ const FilterCreateModal = ({
filterName: filterTitle,
filterColor: filterColor,
};
axios.post("/api/filter", newFilter).then((res) => {
addNewFilter(newFilter);
setFilterTitle("");
setFilterColor("");
onRequestClose();
});
axios
.post("/api/filter", newFilter, {
headers: { Authorization: `Bearer ${storedToken}` },
})
.then((res) => {
console.log(res);
addNewFilter(newFilter);
setFilterTitle("");
setFilterColor("");
onRequestClose();
});
};

return (
Expand Down
12 changes: 9 additions & 3 deletions FE/error/src/utils/filterUtils/FilterDelete.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ import styled from "styled-components";
import axios from "axios";

const FilterDelete = ({ filterID, updateDeleteFilter }) => {
const storedToken = localStorage.getItem("slackToken");

const handleDelete = () => {
axios.delete("/api/filter/" + filterID).then(() => {
updateDeleteFilter(filterID);
});
axios
.delete("/api/filter/" + filterID, {
headers: { Authorization: `Bearer ${storedToken}` },
})
.then(() => {
updateDeleteFilter(filterID);
});
};
return (
<>
Expand Down
17 changes: 13 additions & 4 deletions FE/error/src/utils/filterUtils/FilterModify.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const FilterModify = ({ filterName, filterID }) => {
setClickPosition({ x: rect.left, y: rect.top });
setShowModal(true);
};
const storedToken = localStorage.getItem("slackToken");

const handleTitleChange = (event) => {
setFilterTitle(event.target.value);
Expand All @@ -26,10 +27,18 @@ const FilterModify = ({ filterName, filterID }) => {
filterName: filterTitle,
filterColor: filterColor,
};
axios.post("/api/calendar/filter/" + filterID, modifyFilter).then((res) => {
setShowModal(false);
window.location.reload();
});
axios
.post(
"/api/calendar/filter/" + filterID,
{
headers: { Authorization: `Bearer ${storedToken}` },
},
modifyFilter
)
.then((res) => {
setShowModal(false);
window.location.reload();
});
};

const customStyles = {
Expand Down

0 comments on commit c698f03

Please sign in to comment.