-
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 #41 from Goorm-Lucky7/dev
[PR] dev to main branch
- Loading branch information
Showing
11 changed files
with
89 additions
and
91 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,34 +1,36 @@ | ||
import axios from 'axios'; | ||
import { getNewRefreshToken } from './refresh'; | ||
|
||
export const getAuthAxios = (token: string) => { | ||
export const getAuthAxios = (accessToken?: string) => { | ||
const headersOption = accessToken | ||
? { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${accessToken}`, | ||
} | ||
: { | ||
'Content-Type': 'application/json', | ||
}; | ||
|
||
const authAxios = axios.create({ | ||
baseURL: 'http://211.206.94.24:9999', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
access: `Bearer ${token}`, | ||
}, | ||
headers: headersOption, | ||
withCredentials: true, | ||
}); | ||
|
||
authAxios.interceptors.response.use( | ||
(response) => response, // 성공 응답은 그대로 반환 | ||
authAxios.interceptors.response.use(async (response) => { | ||
if (response.status === 200) { | ||
return response; | ||
} else { | ||
if (response.data && response.data.accessToken) { | ||
const accessToken = response.data.accessToken; | ||
localStorage.setItem('access', accessToken); // 새 토큰을 로컬 스토리지에 저장 | ||
console.log('access token 재발급'); | ||
|
||
async (error) => { | ||
if (error.response && error.response.status === 401) { | ||
try { | ||
const { accessToken } = await getNewRefreshToken(); // 새로운 토큰 가져오기 | ||
error.config.headers['access'] = `Bearer ${accessToken}`; | ||
localStorage.setItem('access', accessToken); | ||
return authAxios(error.config); | ||
} catch (refreshError) { | ||
// 리프레시 토큰 실패 처리 | ||
console.error('Failed to refresh token:', refreshError); | ||
return Promise.reject(refreshError); | ||
} | ||
// 헤더에 새 토큰 반영 | ||
//authAxios.defaults.headers.access = `Bearer ${accessToken}`; | ||
} | ||
return Promise.reject(error); // 다른 모든 에러는 그대로 반환 | ||
}, | ||
); | ||
return response; | ||
} | ||
}); | ||
|
||
return authAxios; | ||
}; |
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 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
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 |
---|---|---|
|
@@ -7,21 +7,25 @@ import { User } from '@/types/auth.ts'; | |
|
||
const UserInfo = () => { | ||
const [userData, setUserData] = useState<User>({ | ||
nickname: 'Soohyun Kim', | ||
profileImage: null, | ||
email: '[email protected]', | ||
introduce: 'hello', | ||
email: '', | ||
nickname: '', | ||
github: '', | ||
blog: '', | ||
introduce: '', | ||
profileImage: '', | ||
}); | ||
|
||
useEffect(() => { | ||
const fetchUserData = async () => { | ||
const data = await getMyPage(); | ||
if (data) { | ||
setUserData({ | ||
nickname: data.nickname, | ||
profileImage: data.profileImage, | ||
email: data.email, | ||
nickname: data.nickname, | ||
github: data.github, | ||
blog: data.blog, | ||
introduce: data.introduce, | ||
profileImage: data.profileImageResDto?.fileUrl, | ||
}); | ||
} | ||
}; | ||
|
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,35 +1,35 @@ | ||
import { IconValues } from "../shared/icon"; | ||
import { IconValues } from '../shared/icon'; | ||
|
||
interface NavItemsProps { | ||
icon: IconValues; | ||
label : string; | ||
path : string; | ||
icon: IconValues; | ||
label: string; | ||
path: string; | ||
} | ||
|
||
export const navItems: NavItemsProps[] = [ | ||
{ | ||
icon: 'home', | ||
label: 'Home', | ||
path : '/' | ||
}, | ||
{ | ||
icon: 'search', | ||
label: 'Search', | ||
path : '/' | ||
}, | ||
{ | ||
icon: 'file', | ||
label: 'Problem', | ||
path : '/post' | ||
}, | ||
{ | ||
icon: 'profile', | ||
label: 'Profile', | ||
path : '/mp' | ||
}, | ||
{ | ||
icon: 'threedot', | ||
label: 'Setting', | ||
path : '/' | ||
} | ||
] | ||
{ | ||
icon: 'home', | ||
label: 'Home', | ||
path: '/', | ||
}, | ||
{ | ||
icon: 'search', | ||
label: 'Search', | ||
path: '/', | ||
}, | ||
{ | ||
icon: 'file', | ||
label: 'Problem', | ||
path: '/post', | ||
}, | ||
{ | ||
icon: 'profile', | ||
label: 'Profile', | ||
path: '/mypage', | ||
}, | ||
{ | ||
icon: 'threedot', | ||
label: 'Setting', | ||
path: '/', | ||
}, | ||
]; |
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