-
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.
Merge pull request #72 from capstone-maru/feat/shared
feat: Apply changes to the Shared API, Add the create mate card form when writing a post
- Loading branch information
Showing
23 changed files
with
1,092 additions
and
502 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,56 @@ | ||
'use client'; | ||
|
||
import axios, { type AxiosRequestConfig, isAxiosError } from 'axios'; | ||
|
||
import { postTokenRefresh } from '@/features/auth'; | ||
import { load, save } from '@/shared/storage'; | ||
|
||
interface AxiosRequestConfigWithRetryCount extends AxiosRequestConfig { | ||
retryCount?: number; | ||
} | ||
|
||
axios.interceptors.response.use( | ||
response => response, | ||
async error => { | ||
if (!isAxiosError(error)) return await Promise.reject(error); | ||
|
||
const refreshToken = load<string>({ type: 'local', key: 'refreshToken' }); | ||
const config = error.config as AxiosRequestConfigWithRetryCount; | ||
if ( | ||
error.response?.status === 401 && | ||
refreshToken != null && | ||
(config?.retryCount ?? 0) < 3 | ||
) { | ||
config.retryCount = (config?.retryCount ?? 0) + 1; | ||
try { | ||
const response = await postTokenRefresh(refreshToken); | ||
|
||
axios.defaults.headers.common.Authorization = `Bearer ${response.data.accessToken}`; | ||
save({ | ||
type: 'local', | ||
key: 'refreshToken', | ||
value: response.data.refreshToken, | ||
}); | ||
save({ | ||
type: 'local', | ||
key: 'expiresIn', | ||
value: `${response.data.expiresIn}`, | ||
}); | ||
|
||
const token = response.data.accessToken; | ||
const newConfig = { | ||
...config, | ||
headers: { | ||
...config.headers, | ||
Authorization: `Bearer ${token}`, | ||
}, | ||
}; | ||
|
||
return await axios(newConfig); | ||
} catch (refreshError) { | ||
return await Promise.reject(refreshError); | ||
} | ||
} | ||
return await Promise.reject(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
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.