Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

authoriztion #86

Merged
merged 4 commits into from
May 30, 2024
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
27 changes: 23 additions & 4 deletions FE/src/api/fetchFilterData.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getAccessToken } from '../utils/userUtils';

const LABELS_API_URI = '/api/labels';
const MEMBERS_API_URI = '/api/members';
const MILESTONES_API_URI = '/api/milestones?isClosed=';
Expand All @@ -10,7 +12,11 @@ const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
*/
export const fetchLabelsData = async () => {
try {
const response = await fetch(`${import.meta.env.VITE_TEAM_SERVER}${LABELS_API_URI}`);
const response = await fetch(`${import.meta.env.VITE_TEAM_SERVER}${LABELS_API_URI}`, {
headers: {
Authorization: `Bearer ${getAccessToken()}`,
},
});
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);

if (response.status === 200) {
Expand All @@ -26,7 +32,11 @@ export const fetchLabelsData = async () => {
*/
export const fetchMembersData = async () => {
try {
const response = await fetch(`${import.meta.env.VITE_TEAM_SERVER}${MEMBERS_API_URI}`);
const response = await fetch(`${import.meta.env.VITE_TEAM_SERVER}${MEMBERS_API_URI}`, {
headers: {
Authorization: `Bearer ${getAccessToken()}`,
},
});
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);

if (response.status === 200) {
Expand All @@ -46,7 +56,11 @@ export const fetchMilestonesData = async (isClosed) => {
try {
// await delay(5000);

const response = await fetch(`${import.meta.env.VITE_TEAM_SERVER}${MILESTONES_API_URI}${isClosed}`);
const response = await fetch(`${import.meta.env.VITE_TEAM_SERVER}${MILESTONES_API_URI}${isClosed}`, {
headers: {
Authorization: `Bearer ${getAccessToken()}`,
},
});
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);

if (response.status === 200) {
Expand Down Expand Up @@ -78,7 +92,12 @@ export const fetchIssueListData = async (isClosedParam, authorIdParam, assigneeI
const response = await fetch(
`${
import.meta.env.VITE_TEAM_SERVER
}${ISSUE_LIST_API_URI}?isClosed=${isClosed}&authorId=${authorId}&assigneeId=${assigneeId}&labelName=${labelName}&milestoneName=${milestoneNameParam}&noValues=${noValues}`
}${ISSUE_LIST_API_URI}?isClosed=${isClosed}&authorId=${authorId}&assigneeId=${assigneeId}&labelName=${labelName}&milestoneName=${milestoneNameParam}&noValues=${noValues}`,
{
headers: {
Authorization: `Bearer ${getAccessToken()}`,
},
}
);
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);

Expand Down
22 changes: 21 additions & 1 deletion FE/src/api/fetchIssueData.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getAccessToken } from '../utils/userUtils';

const ISSUE_DEFAULT_API_URI = '/api/issues';
const ISSUE_COMMENTS_DEFAULT_API_URI = '/api/comments';
const ISSUE_DEFAULT_FILE_URI = '/api/files';
Expand All @@ -12,7 +14,11 @@ export const fetchIssueDetailData = async (issueId) => {

try {
// await delay(2000);
const response = await fetch(`${import.meta.env.VITE_TEAM_SERVER}${ISSUE_DEFAULT_API_URI}/${issueId}`);
const response = await fetch(`${import.meta.env.VITE_TEAM_SERVER}${ISSUE_DEFAULT_API_URI}/${issueId}`, {
headers: {
Authorization: `Bearer ${getAccessToken()}`,
},
});
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);

if (response.status === 200) {
Expand All @@ -34,6 +40,7 @@ export const fetchIssueStateToggle = async (toIssueState, issueIds) => {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${getAccessToken()}`,
},
body: JSON.stringify({ issueIds }),
});
Expand Down Expand Up @@ -64,6 +71,7 @@ export const fetchDeleteIssue = async (issueId) => {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${getAccessToken()}`,
},
});

Expand Down Expand Up @@ -94,6 +102,7 @@ export const fetchModifyIssueTitle = async (title, issueId) => {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${getAccessToken()}`,
},
body: JSON.stringify({ title }),
});
Expand Down Expand Up @@ -125,6 +134,7 @@ export const fetchModifyIssueContent = async (content, fileId, issueId) => {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${getAccessToken()}`,
},
body: JSON.stringify({ content, fileId }),
});
Expand Down Expand Up @@ -156,6 +166,7 @@ export const fetchModifyIssueComment = async (content, fileId, commentId) => {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${getAccessToken()}`,
},
body: JSON.stringify({ content, fileId }),
});
Expand Down Expand Up @@ -188,6 +199,7 @@ export const fetchCreateIssueComment = async (writerId, content, issueId, fileId
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${getAccessToken()}`,
},
body: JSON.stringify({ writerId, content, issueId, fileId }),
});
Expand Down Expand Up @@ -218,6 +230,7 @@ export const fetchDeleteComment = async (commentId) => {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${getAccessToken()}`,
},
});

Expand Down Expand Up @@ -248,6 +261,7 @@ export const fetchModifyIssueLabels = async (issueId, labelIds) => {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${getAccessToken()}`,
},
body: JSON.stringify({ labelIds }),
});
Expand Down Expand Up @@ -279,6 +293,7 @@ export const fetchModifyIssueAssignees = async (issueId, assigneeIds) => {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${getAccessToken()}`,
},
body: JSON.stringify({ assigneeIds }),
});
Expand Down Expand Up @@ -310,6 +325,7 @@ export const fetchModifyIssueMilestone = async (issueId, milestoneId) => {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${getAccessToken()}`,
},
body: JSON.stringify({ milestoneId }),
});
Expand Down Expand Up @@ -339,6 +355,9 @@ export const fetchUploadFile = async (formData) => {
try {
const response = await fetch(`${import.meta.env.VITE_TEAM_SERVER}${ISSUE_DEFAULT_FILE_URI}`, {
method: 'POST',
headers: {
Authorization: `Bearer ${getAccessToken()}`,
},
body: formData,
});

Expand Down Expand Up @@ -373,6 +392,7 @@ export const fetchCreateNewIssue = async (title, content, authorId, milestoneId,
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${getAccessToken()}`,
},
body: JSON.stringify({ title, content, authorId, milestoneId, fileId, labelIds, assigneeIds }),
});
Expand Down
8 changes: 7 additions & 1 deletion FE/src/api/fetchLabelData.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getAccessToken } from '../utils/userUtils';

const LABEL_DEFAULT_API_URI = '/api/labels';
const HOME_DEFAULT_API_URI = '/api/home/components';

Expand All @@ -12,7 +14,11 @@ const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
export const fetchLabelMilestoneCountData = async () => {
try {
// await delay(2000);
const response = await fetch(`${import.meta.env.VITE_TEAM_SERVER}${HOME_DEFAULT_API_URI}`);
const response = await fetch(`${import.meta.env.VITE_TEAM_SERVER}${HOME_DEFAULT_API_URI}`, {
headers: {
Authorization: `Bearer ${getAccessToken()}`,
},
});
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);

if (response.status === 200 || response.status === 201) {
Expand Down
3 changes: 2 additions & 1 deletion FE/src/router/ProtectedRoute.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React from 'react';
import { Navigate } from 'react-router-dom';
import { getAccessToken } from '../utils/userUtils';

export default function ProtectedRoute({ children }) {
//TODO: 토큰을 기반으로 로그인 상태 확인
const isUserAuthenticated = localStorage.getItem('storeUserData');
const isUserAuthenticated = getAccessToken();

if (!isUserAuthenticated) return <Navigate to="/members/login" />;

Expand Down
15 changes: 9 additions & 6 deletions FE/src/utils/userUtils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
export const getUserId = () => {
return localStorage.getItem('storeUserData') ? JSON.parse(localStorage.getItem('storeUserData')).memberProfile.id : '';
};
export const getUserImg = () => {
return localStorage.getItem('storeUserData') ? JSON.parse(localStorage.getItem('storeUserData')).memberProfile.imgUrl : '';
};
export const getUserId = () => (localStorage.getItem('storeUserData') ? JSON.parse(localStorage.getItem('storeUserData')).memberProfile.id : '');

export const getUserImg = () => (localStorage.getItem('storeUserData') ? JSON.parse(localStorage.getItem('storeUserData')).memberProfile.imgUrl : '');

export const getAccessToken = () =>
localStorage.getItem('storeUserData') ? JSON.parse(localStorage.getItem('storeUserData')).tokenResponse.accessToken : '';

export const getRefreshToken = () =>
localStorage.getItem('storeUserData') ? JSON.parse(localStorage.getItem('storeUserData')).tokenResponse.refreshToken : '';
Loading