-
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.
feat: 신규 유저일 경우 정보를 서버에 저장하고 불러오도록 대응
- Loading branch information
Showing
4 changed files
with
24 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,30 @@ | ||
import uoslifeBridge from '../bridge'; | ||
import { FetchMethodType } from './types'; | ||
|
||
export default class APIClient { | ||
static async APIclient<ResponseType>({ | ||
url, | ||
method = 'GET', | ||
}: { | ||
url: string; | ||
method?: FetchMethodType; | ||
}): Promise<ResponseType> { | ||
try { | ||
const response = await this.fetchWithToken(`/core/${url}`); | ||
const response = await this.fetchWithToken(`/core/${url}`, method); | ||
return await response?.json(); | ||
} catch (error) { | ||
throw Error(); | ||
} | ||
} | ||
static async fetchWithToken(input: RequestInfo | URL) { | ||
static async fetchWithToken( | ||
input: RequestInfo | URL, | ||
method: FetchMethodType, | ||
) { | ||
const { accessToken } = await uoslifeBridge.getAccessToken(); | ||
if (accessToken) | ||
return await fetch(input, { | ||
headers: { Authorization: `Bearer ${accessToken}` }, | ||
method, | ||
}); | ||
} | ||
} |
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