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

[PR] 공통 UI 컴포넌트 조정 #43

Merged
merged 5 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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/apis/authAxios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const getAuthAxios = (accessToken?: string) => {
};

const authAxios = axios.create({
baseURL: 'http://211.206.94.24:9999',
baseURL: 'http://13.124.54.157:8080',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이부분 .env로 빼서 관리합시다.

headers: headersOption,
withCredentials: true,
});
Expand Down
47 changes: 46 additions & 1 deletion src/apis/mypage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getAuthAxios } from './authAxios';

/** MYPAGE API */
export const getMyPage = async () => {
export const getUserInfo = async () => {
const access = localStorage.getItem('access');

if (!access) {
Expand All @@ -14,3 +14,48 @@ export const getMyPage = async () => {
console.log(response.data);
return response.data;
};

/** MYPAGE 이미지 수정 */
export const putImage = async () => {
const access = localStorage.getItem('access');

if (!access) {
console.error('Access token is missing or invalid');
throw new Error('Access token is missing or invalid');
}

const authAxios = getAuthAxios(access);
const response = await authAxios.put('/api/mypage/users/image');
console.log(response.data);
return response.data;
};

interface MypagePosts {
pageParam: number;
problemType: 'created' | 'liked' | 'solved';
}

/** MYPAGE 게시글 조회 */
export const getMypagePosts = async ({ pageParam = 0, problemType }: MypagePosts) => {
const access = localStorage.getItem('access');

if (!access) {
console.error('Access token is missing or invalid');
throw new Error('Access token is missing or invalid');
}

const authAxios = getAuthAxios(access);

// problemType을 헤더에 포함하여 요청을 보냅니다.
const response = await authAxios.get('/api/mypage/posts', {
headers: {
problemType: problemType,
},
params: {
page: pageParam,
},
});

console.log(response.data);
return response.data;
};
16 changes: 15 additions & 1 deletion src/apis/userapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,21 @@ export const postSignup = async ({
};

export const logout = () => {
// 로컬 스토리지에서 토큰 제거
localStorage.removeItem('access');
window.location.href = '/login';
};

/** 유저정보 수정 */
export const putUser = async () => {
const access = localStorage.getItem('access');

if (!access) {
console.error('Access token is missing or invalid');
throw new Error('Access token is missing or invalid');
}

const authAxios = getAuthAxios(access);
const response = await authAxios.put('/api/mypage/users');
console.log(response.data);
return response.data;
};