-
Notifications
You must be signed in to change notification settings - Fork 0
feat: 카카오 로그인 구현 (회원가입 기능 완료 전) #97
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,29 @@ | ||
| import { create } from 'zustand'; | ||
| import { persist } from 'zustand/middleware'; | ||
|
|
||
| interface AuthStore { | ||
| accessToken: string | null; | ||
| refreshToken: string | null; | ||
| setAccessToken: (token: string | null) => void; | ||
| setRefreshToken: (token: string | null) => void; | ||
|
|
||
| isModalOpen: boolean; | ||
| openModal: () => void; | ||
| closeModal: () => void; | ||
| } | ||
|
|
||
| const useAuthStore = create<AuthStore>(set => ({ | ||
| isModalOpen: false, | ||
| openModal: () => set({ isModalOpen: true }), | ||
| closeModal: () => set({ isModalOpen: false }), | ||
| })); | ||
| export const useAuthStore = create<AuthStore>()( | ||
| persist( | ||
| (set) => ({ | ||
| accessToken: null, | ||
| refreshToken: null, | ||
| setAccessToken: (token) => set({ accessToken: token }), | ||
| setRefreshToken: (token) => set({ refreshToken: token }), | ||
| isModalOpen: false, | ||
| openModal: () => set({ isModalOpen: true }), | ||
| closeModal: () => set({ isModalOpen: false }), | ||
| }), { name: 'auth-storage' } | ||
| ) | ||
| ); | ||
|
|
||
| export default useAuthStore; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,20 +6,21 @@ import useAuthStore from '../../../app/provider/authStore'; | |
| export const axiosClient = axios.create({ | ||
| baseURL: 'http://ec2-3-35-48-123.ap-northeast-2.compute.amazonaws.com:8080/api/v1', | ||
| timeout: 3000, | ||
| withCredentials: true, | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| Authorization: `Bearer ${import.meta.env.VITE_HEADER_TOKEN}`, | ||
| //Authorization: `Bearer `, | ||
|
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 인증 관련 코드가 일관되지 않게 주석 처리되었습니다. Authorization 헤더와 토큰 설정 로직이 주석 처리되었지만, 완전히 제거되지 않았습니다. 이는 코드 품질과 유지보수성을 저하시킵니다. 또한 line 49에서는 여전히 다음과 같이 개선할 것을 제안합니다: headers: {
'Content-Type': 'application/json',
- //Authorization: `Bearer `,
},
});
axiosClient.interceptors.request.use(
config => {
- //const token = Cookies.get('access_token');
- //zustand 사용함으로써 코드변경 할 듯 현재는 임시 입니다.
- // const token = useAuthStore.getState().accessToken;
- // if (token) {
- // config.headers.Authorization = `Bearer ${token}`;
- // }
+ const token = useAuthStore.getState().accessToken;
+ if (token) {
+ config.headers.Authorization = `Bearer ${token}`;
+ }
return config;그리고 아래의 에러 처리 부분도 수정이 필요합니다: // 401(토큰 만료)일 경우 로그아웃 처리 or 토큰 갱신 가능
if (errorInfo.status === 401) {
- Cookies.remove('access_token');
+ Cookies.remove('access-token');
+ Cookies.remove('refresh-token');
useAuthStore.getState().openModal();
}Also applies to: 18-23 |
||
| }, | ||
| }); | ||
|
|
||
| axiosClient.interceptors.request.use( | ||
| config => { | ||
| const token = Cookies.get('access_token'); | ||
| //const token = Cookies.get('access_token'); | ||
| //zustand 사용함으로써 코드변경 할 듯 현재는 임시 입니다. | ||
|
|
||
| if (token) { | ||
| config.headers.Authorization = `Bearer ${token}`; | ||
| } | ||
| // const token = useAuthStore.getState().accessToken; | ||
| // if (token) { | ||
| // config.headers.Authorization = `Bearer ${token}`; | ||
| // } | ||
|
|
||
| return config; | ||
| }, | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,6 +9,12 @@ interface LoginModalProps { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const LoginModal = ({ onClose }: LoginModalProps) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const kakaoLogin = () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| window.location.href = 'http://ec2-3-35-48-123.ap-northeast-2.compute.amazonaws.com:8080/oauth2/authorization/kakao'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const gooleLogin = () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| window.location.href = 'http://ec2-3-35-48-123.ap-northeast-2.compute.amazonaws.com:8080/oauth2/authorization/google'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+12
to
+17
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 OAuth 로그인 함수 구현 개선이 필요합니다. OAuth 로그인 함수에 다음과 같은 개선이 필요합니다:
다음과 같이 개선할 것을 제안합니다: - const kakaoLogin = () => {
- window.location.href = 'http://ec2-3-35-48-123.ap-northeast-2.compute.amazonaws.com:8080/oauth2/authorization/kakao';
- };
- const gooleLogin = () => {
- window.location.href = 'http://ec2-3-35-48-123.ap-northeast-2.compute.amazonaws.com:8080/oauth2/authorization/google';
- }
+ const [isLoading, setIsLoading] = useState(false);
+
+ const kakaoLogin = () => {
+ try {
+ setIsLoading(true);
+ window.location.href = import.meta.env.VITE_API_BASE_URL + '/oauth2/authorization/kakao';
+ } catch (error) {
+ console.error('카카오 로그인 중 오류 발생:', error);
+ setIsLoading(false);
+ }
+ };
+
+ const googleLogin = () => {
+ try {
+ setIsLoading(true);
+ window.location.href = import.meta.env.VITE_API_BASE_URL + '/oauth2/authorization/google';
+ } catch (error) {
+ console.error('구글 로그인 중 오류 발생:', error);
+ setIsLoading(false);
+ }
+ }📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <motion.div | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| initial={{ y: '-100vh', opacity: 0 }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -30,15 +36,15 @@ const LoginModal = ({ onClose }: LoginModalProps) => { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <HorizontalCardButton | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| iconPath={<img src={kakao} alt="카카오 아이콘" className="" />} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| label="카카오 로그인" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onClick={() => {}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onClick={kakaoLogin} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| className="mx-auto my-auto" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div className="flex items-center w-full h-12 bg-white gap-4 rounded-full"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <HorizontalCardButton | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| iconPath={<img src={google} alt="구글 아이콘" className="" />} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| label="Google 로그인" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onClick={() => {}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onClick={gooleLogin} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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. 구글 로그인 버튼에 오타가 있는 함수를 사용하고 있습니다. 구글 로그인 기능을 호출하는 함수명에 오타가 있습니다. - onClick={gooleLogin}
+ onClick={googleLogin}📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| className="mx-auto my-auto" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
토큰 관리 로직에 보안 및 최적화 문제가 있습니다.
다음과 같은 문제점이 있습니다:
다음과 같이 개선할 것을 제안합니다:
const { setAccessToken, setRefreshToken } = useAuthStore(); useEffect(() => { const accessToken = Cookies.get('access-token'); const refreshToken = Cookies.get('refresh-token'); - console.log("access-token:", accessToken); - console.log("refresh-token:", refreshToken); - if (accessToken) { setAccessToken(accessToken); } if (refreshToken) { setRefreshToken(refreshToken); } - }, []); + }, [setAccessToken, setRefreshToken]);📝 Committable suggestion