-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 개개인 장소 입력 화면 구현 및 api 연동 코드 작성
✨ feat: 개개인 장소 입력 화면 구현 및 api 연동 코드 작성
- Loading branch information
Showing
14 changed files
with
676 additions
and
35 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import axios from 'axios'; | ||
import axiosInstance from '.'; | ||
|
||
export const fetchIsValidRoomId = async (roomId: string) => { | ||
const { data } = await axios.get(`/api?roomId=${roomId}`); | ||
return data; | ||
}; | ||
|
||
export const fetchSavePlace = async (data: any) => { | ||
return axiosInstance.post('/api/place-rooms', data, { | ||
withCredentials: true, | ||
}); | ||
}; | ||
|
||
export const fetchRoomUsersInfo = async (roomId: string) => { | ||
const { data } = await axiosInstance.get(`/api/place-rooms/${roomId}/users`); | ||
return data; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// login이 완료된 사람의 요청의 경우 axiosInstance를 사용하여 요청한다 | ||
|
||
import axios from 'axios'; | ||
|
||
const REFRESH_URL = ''; // Refresh Token을 사용해 새로운 Access Token을 받을때 요청하는 URL | ||
|
||
// access token 재발급하는 함수 | ||
const getNewToken = async () => { | ||
try { | ||
const accessToken = ''; | ||
const refreshToken = ''; | ||
return { accessToken, refreshToken }; | ||
// Refresh Token을 사용하여 REFRESH_URL로 요청을 하여 새로운 Access Token, Refresh Token을 받아와 2값을 리턴하도록 구현 | ||
} catch (e) { | ||
// Refresh Token에 문제가 있는 상황이며 이는 올바르지 않은 유저 로그인 과정이므로, 로그아웃 처리 | ||
logout(); | ||
} | ||
}; | ||
|
||
// 로그 아웃 함수 | ||
const logout = () => { | ||
localStorage.removeItem('accessToken'); | ||
}; | ||
|
||
const axiosInstance = axios.create({ | ||
baseURL: '', | ||
}); | ||
|
||
// 요청 인터셉터 | ||
axiosInstance.interceptors.request.use( | ||
(config) => { | ||
// 헤더에 엑세스 토큰 담기 | ||
const accessToken: string | null = localStorage.getItem('accessToken'); | ||
if (accessToken) { | ||
config.headers.Authorization = `Bearer ${accessToken}`; | ||
} | ||
return config; | ||
}, | ||
(error) => { | ||
return Promise.reject(error); | ||
}, | ||
); | ||
|
||
// 응답 인터셉터 | ||
axiosInstance.interceptors.response.use( | ||
(response) => { | ||
return response; | ||
}, | ||
async (error) => { | ||
const { config, response } = error; | ||
// 401에러가 아니거나 재요청이거나 refresh 요청인 경우 그냥 에러 발생 | ||
if (response.status !== 401 || config.sent || config.url === REFRESH_URL) { | ||
return Promise.reject(error); | ||
} | ||
// 아닌 경우 토큰 갱신 | ||
config.sent = true; // 무한 재요청 방지 | ||
const newToken = await getNewToken(); | ||
if (newToken) { | ||
localStorage.setItem('accessToken', newToken.accessToken); | ||
localStorage.setItem('refreshToken', newToken.refreshToken); | ||
config.headers.Authorization = `Bearer ${newToken.accessToken}`; | ||
} | ||
return axios(config); // 재요청 | ||
}, | ||
); | ||
|
||
export default axiosInstance; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Login() { | ||
return <h1>로그인</h1>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import SideBar from '@/components/Sidebar'; | ||
import { Outlet } from 'react-router-dom'; | ||
import styled from 'styled-components'; | ||
|
||
export default function EnterLocation() { | ||
return ( | ||
<Container className="max-w-[1800px]"> | ||
<SideBar /> | ||
<Content> | ||
<Title className="text-4xl font-medium pt-9">모두의 중간</Title> | ||
<Textbox className="rounded-lg"> | ||
<p>상대방에게 링크를 공유하여 주소를 입력하게 하고 중간 지점을 찾아보세요!</p> | ||
</Textbox> | ||
<Outlet /> | ||
</Content> | ||
</Container> | ||
); | ||
} | ||
|
||
const Container = styled.div` | ||
display: flex; | ||
margin: 0 auto; | ||
width: 100vw; | ||
`; | ||
|
||
const Content = styled.div` | ||
width: 80%; | ||
min-width: 1024px; | ||
margin: 0 auto; | ||
display: flex; | ||
flex-direction: column; | ||
gap: 20px; | ||
align-items: center; | ||
`; | ||
|
||
const Title = styled.h1``; | ||
|
||
const Textbox = styled.div` | ||
width: 55%; | ||
min-width: 700px; | ||
background: rgba(81, 66, 255, 0.1); | ||
color: ${(props) => props.theme.mainColor}; | ||
padding: 10px 5px; | ||
font-size: 18px; | ||
text-align: center; | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Loading() { | ||
return <h1>로딩중...</h1>; | ||
} |
Oops, something went wrong.