-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* rename AuthContext to ApiProvider * feat: ApiProvider 도입 철회, axios의 client만 도입 * feat: 흩어져 있던 axios 모음 * error handling * feat: axios client로 모두 수정
- Loading branch information
1 parent
99265cc
commit d88cdce
Showing
20 changed files
with
122 additions
and
108 deletions.
There are no files selected for viewing
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import axios, { AxiosInstance } from 'axios'; | ||
|
||
export const apiClient: AxiosInstance = axios.create({ | ||
baseURL: import.meta.env.VITE_BASE_URL as string, | ||
withCredentials: true, | ||
}); |
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 |
---|---|---|
@@ -1,14 +1,16 @@ | ||
import axios from 'axios'; | ||
import { AxiosError } from 'axios'; | ||
import { RoomCreateType } from '../types/RoomCreateType'; | ||
|
||
const VITE_BASE_URL = import.meta.env.VITE_BASE_URL as string; | ||
import { apiClient } from './apiClient'; | ||
|
||
export async function createRoom(): Promise<RoomCreateType | undefined> { | ||
const response = await axios.post( | ||
`${VITE_BASE_URL}/room`, | ||
{}, | ||
{ withCredentials: true }, | ||
); | ||
|
||
return response.data; | ||
try { | ||
const { data } = await apiClient.post('/room', {}); | ||
return data; | ||
} catch (error) { | ||
if (error instanceof AxiosError) { | ||
// TODO: 이거 session로직 수정되면 여기도 고쳐야 됨 | ||
// 세션에서 현재 유저가 방에 참가중인지, 어떤 방에 참가중인지 정보를 받아 올 수 있어야 함 | ||
alert(error.response!.data.message); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import axios from 'axios'; | ||
|
||
const VITE_BASE_URL = import.meta.env.VITE_BASE_URL as string; | ||
import { apiClient } from './apiClient'; | ||
|
||
export async function exitRoom() { | ||
await axios.post(`${VITE_BASE_URL}/room/exit`, {}, { withCredentials: true }); | ||
try { | ||
await apiClient.post('/room/exit'); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
} |
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,11 @@ | ||
import { CreateUser } from '../types/CreateUserType'; | ||
import { apiClient } from './apiClient'; | ||
|
||
export async function getSession(): Promise<CreateUser | undefined> { | ||
try { | ||
const { data }: { data: CreateUser } = await apiClient.get('/session'); | ||
return data; | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,13 +1,9 @@ | ||
import axios from 'axios'; | ||
|
||
const VITE_BASE_URL = import.meta.env.VITE_BASE_URL as string; | ||
import { apiClient } from './apiClient'; | ||
|
||
export async function joinRoom(roomCode: string) { | ||
await axios.post( | ||
`${VITE_BASE_URL}/room/join`, | ||
{ code: roomCode }, | ||
{ | ||
withCredentials: true, | ||
}, | ||
); | ||
try { | ||
await apiClient.post('/room/join', { code: roomCode }); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
} |
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,9 @@ | ||
import { apiClient } from './apiClient'; | ||
|
||
export async function logout() { | ||
try { | ||
await apiClient.get('/auth/logout'); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
} |
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,14 @@ | ||
import { apiClient } from './apiClient'; | ||
|
||
type mockUser = { | ||
username: string; | ||
password: string; | ||
}; | ||
|
||
export async function mockLoginApi(mockUser: mockUser) { | ||
try { | ||
return await apiClient.post('/auth/mock', mockUser); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,22 +1,21 @@ | ||
import axios from 'axios'; | ||
import { ProblemResponse } from '../types/Problem'; | ||
|
||
export async function searchProblem(searchKeyword: string): Promise<ProblemResponse[]> { | ||
const VITE_BASE_URL = import.meta.env.VITE_BASE_URL as string; | ||
import { apiClient } from './apiClient'; | ||
|
||
if(!searchKeyword) return Promise.resolve([]); | ||
export async function searchProblem( | ||
searchKeyword: string, | ||
): Promise<ProblemResponse[]> { | ||
if (!searchKeyword) return Promise.resolve([]); | ||
|
||
return await axios | ||
.get(`${VITE_BASE_URL}/problem`, { | ||
try { | ||
const { data } = await apiClient.get('/problem', { | ||
params: { | ||
searchKeyword, | ||
}, | ||
}) | ||
.then((res) => { | ||
return res.data || []; | ||
}) | ||
.catch((err) => { | ||
console.log(err); | ||
return []; | ||
}); | ||
return data; | ||
} catch (error) { | ||
console.log(error); | ||
return []; | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.