-
Notifications
You must be signed in to change notification settings - Fork 0
[Refactor] 스토리지 변경 & 중복 호출 방지 제거 #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { API_ENDPOINTS } from '../constants/api'; | ||
|
|
||
| export const getMypage = async () => { | ||
| const accessToken = sessionStorage.getItem('accessToken'); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Guard missing token; tighten headers Avoid sending const accessToken = sessionStorage.getItem('accessToken');
+ if (!accessToken) {
+ throw new Error('Missing access token');
+ }
try {
const response = await fetch(`${API_ENDPOINTS.users.base}/my-page`, {
method: 'GET',
headers: {
- 'Authorization': `Bearer ${accessToken}`,
- 'Content-Type': 'application/json',
+ Authorization: `Bearer ${accessToken}`,
+ Accept: 'application/json',
},
credentials: 'include',
});Also applies to: 9-14 🤖 Prompt for AI Agents |
||
|
|
||
| try { | ||
| const response = await fetch(`${API_ENDPOINTS.users.base}/my-page`, { | ||
| method: 'GET', | ||
| headers: { | ||
| 'Authorization': `Bearer ${accessToken}`, | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| credentials: 'include', | ||
| }); | ||
|
|
||
| if (!response.ok) { | ||
| const errorData = await response.json(); | ||
| console.error('Error response:', response.status, errorData); | ||
| throw new Error(`HTTP error! status: ${response.status}`); | ||
| } | ||
|
|
||
| const data = await response.json(); | ||
| return data; | ||
| } catch (error) { | ||
| console.error('Fetch error:', error); | ||
| throw error; | ||
| } | ||
| }; | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { API_ENDPOINTS } from '../constants/api'; | ||
|
|
||
| export const getTierLeagues = async (id: number, num: number) => { | ||
| const accessToken = sessionStorage.getItem('accessToken'); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Token guard + lean GET headers Same fix as other APIs. const accessToken = sessionStorage.getItem('accessToken');
+ if (!accessToken) {
+ throw new Error('Missing access token');
+ }
@@
headers: {
- 'Authorization': `Bearer ${accessToken}`,
- 'Content-Type': 'application/json',
+ Authorization: `Bearer ${accessToken}`,
+ Accept: 'application/json',
},
credentials: 'include', Also applies to: 9-14 🤖 Prompt for AI Agents |
||
|
|
||
| try { | ||
| const response = await fetch(API_ENDPOINTS.leagues.tier(id, num), { | ||
| method: 'GET', | ||
| headers: { | ||
| 'Authorization': `Bearer ${accessToken}`, | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| credentials: 'include', | ||
| }); | ||
|
|
||
| if (!response.ok) { | ||
| const errorData = await response.json(); | ||
| console.error('Error response:', response.status, errorData); | ||
| throw new Error(`HTTP error! status: ${response.status}`); | ||
| } | ||
|
|
||
| const data = await response.json(); | ||
| console.log(data); | ||
| return data; | ||
| } catch (error) { | ||
| console.error('Fetch error:', error); | ||
| throw error; | ||
| } | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { API_ENDPOINTS } from '../constants/api'; | ||
|
|
||
| export const getUserLeagues = async (num: number) => { | ||
| const accessToken = sessionStorage.getItem('accessToken'); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Token guard + lean GET headers Avoid const accessToken = sessionStorage.getItem('accessToken');
+ if (!accessToken) {
+ throw new Error('Missing access token');
+ }
try {
const response = await fetch(API_ENDPOINTS.leagues.user(num), {
method: 'GET',
headers: {
- 'Authorization': `Bearer ${accessToken}`,
- 'Content-Type': 'application/json',
+ Authorization: `Bearer ${accessToken}`,
+ Accept: 'application/json',
},
credentials: 'include',
});Also applies to: 9-14 🤖 Prompt for AI Agents |
||
|
|
||
| try { | ||
| const response = await fetch(API_ENDPOINTS.leagues.user(num), { | ||
| method: 'GET', | ||
| headers: { | ||
| 'Authorization': `Bearer ${accessToken}`, | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| credentials: 'include', | ||
| }); | ||
|
|
||
| if (!response.ok) { | ||
| const errorData = await response.json(); | ||
| console.error('Error response:', response.status, errorData); | ||
| throw new Error(`HTTP error! status: ${response.status}`); | ||
| } | ||
|
|
||
| const data = await response.json(); | ||
| console.log(data); | ||
| return data; | ||
| } catch (error) { | ||
| console.error('Fetch error:', error); | ||
| throw error; | ||
| } | ||
| }; | ||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,7 +3,7 @@ import type { AxiosResponse } from 'axios'; | |||||||||||
| import { API_ENDPOINTS } from '../constants/api'; | ||||||||||||
|
|
||||||||||||
| export const PatchOnBoarding = async (nickname: string, profilePhotoNumber: number) => { | ||||||||||||
| const accessToken = localStorage.getItem('accessToken'); | ||||||||||||
| const accessToken = sessionStorage.getItem('accessToken'); | ||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Avoid sending “Bearer null” when token is missing. Guard early and surface an actionable error (or redirect) instead of hitting the API with an invalid header. -const accessToken = sessionStorage.getItem('accessToken');
+const accessToken = sessionStorage.getItem('accessToken');
+if (!accessToken) {
+ throw new Error('Unauthenticated: missing access token. Please log in again.');
+}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||
|
|
||||||||||||
| try { | ||||||||||||
| const response: AxiosResponse = await axios.patch( | ||||||||||||
|
|
||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Guard sessionStorage for SSR
Avoid accessing Web APIs during SSR.
📝 Committable suggestion
🤖 Prompt for AI Agents