generated from Team-INSERT/Repository-generator-Frontend
-
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.
Merge pull request #67 from Team-INSERT/fix/token
액세스 토큰 재발급 오류 수정
- Loading branch information
Showing
6 changed files
with
27 additions
and
41 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,20 +1,11 @@ | ||
import { isAxiosError } from "axios"; | ||
import { toast } from "react-toastify"; | ||
|
||
const throwAxiosError = (err: unknown) => { | ||
if (!isAxiosError(err)) | ||
return { | ||
data: "", | ||
status: "", | ||
message: "", | ||
}; | ||
if (isAxiosError(err) && err.response) { | ||
const { code, status, message } = err.response.data; | ||
|
||
const data = err?.response?.data; | ||
const { code, status, message } = data; | ||
console.log(err); | ||
toast.error("오류가 발생했습니다."); | ||
|
||
return { code, status, message }; | ||
return { code, status, message }; | ||
} | ||
}; | ||
|
||
export default throwAxiosError; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
import { TOKEN } from "@/constants/"; | ||
import Storage from "@/apis/storage"; | ||
import httpClient from "../httpClient"; | ||
import axios from "axios"; | ||
|
||
const instance = axios.create({ | ||
baseURL: process.env.NEXT_PUBLIC_BASE_URL, | ||
}); | ||
|
||
const refresh = async () => { | ||
try { | ||
const { data } = await httpClient.refresh.put({ | ||
refreshToken: `${Storage.getItem(TOKEN.REFRESH)}`, | ||
}); | ||
Storage.setItem(TOKEN.ACCESS, data.accessToken); | ||
} catch (err) { | ||
Storage.clear(); | ||
} | ||
const { data } = await instance.put("/api/auth/refresh/access", { | ||
refreshToken: `${Storage.getItem(TOKEN.REFRESH)}`, | ||
}); | ||
Storage.setItem(TOKEN.ACCESS, data.accessToken); | ||
}; | ||
|
||
export default refresh; |
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