-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 이메일 로그인 시 로그인 상태 제대로 갱신되지 않는 문제 수정 (로그인 관련 전역상태 코드 수정) - 로그인 상태로 새로고침 했을 때 로그인 해제되는 부분 수정 - 로그아웃 시 로컬 스토리지에 액세스 토큰 계속 남아있던 문제 해결 Issues #94
- Loading branch information
1 parent
ea57823
commit 0a9341c
Showing
8 changed files
with
101 additions
and
152 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
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,47 +1,40 @@ | ||
import React from 'react'; | ||
import { GoogleOAuthProvider, GoogleLogin, useGoogleOneTapLogin } from '@react-oauth/google'; | ||
import { useDispatch } from 'react-redux'; | ||
import { setLoginState } from '../../reducer/member/loginSlice'; | ||
import React from "react"; | ||
import { GoogleOAuthProvider, GoogleLogin, useGoogleOneTapLogin } from "@react-oauth/google"; | ||
import { useDispatch } from "react-redux"; | ||
import { setLoginState } from "../../reducer/member/loginSlice"; | ||
|
||
const GoogleSignInComponent: React.FC = () => { | ||
|
||
const dispatch = useDispatch(); // Redux의 dispatch 함수를 사용하기 위해 가져옵니다. | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const handleSuccess = (credentialResponse: any) => { | ||
console.log(credentialResponse); | ||
|
||
const token = credentialResponse.token; // 실제 응답에서 토큰의 경로가 어떤지 확인하고 수정해야 합니다. | ||
localStorage.setItem('authToken', token); // 토큰을 localStorage에 저장 | ||
|
||
// 로그인 성공 시 전역 상태를 업데이트합니다. | ||
dispatch(setLoginState({ | ||
memberId: credentialResponse.memberId, // memberId는 예시입니다. 실제 값에 맞게 수정해야 합니다. | ||
isLoggedIn: 1, | ||
})); | ||
}; | ||
|
||
const handleError = () => { | ||
console.log('Login Failed'); | ||
}; | ||
|
||
// One-tap 로그인 (선택적) | ||
useGoogleOneTapLogin({ | ||
onSuccess: handleSuccess, | ||
onError: handleError, | ||
}); | ||
|
||
return ( | ||
<GoogleOAuthProvider clientId=" | ||
690344785644-2oj84rcukd2rhu3o56gbq6rahap16m37.apps.googleusercontent.com"> | ||
<GoogleLogin | ||
onSuccess={handleSuccess} | ||
onError={handleError} | ||
useOneTap | ||
/> | ||
</GoogleOAuthProvider> | ||
); | ||
const dispatch = useDispatch(); // Redux의 dispatch 함수를 사용하기 위해 가져옵니다. | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const handleSuccess = (credentialResponse: any) => { | ||
console.log(credentialResponse); | ||
|
||
const token = credentialResponse.token; // 실제 응답에서 토큰의 경로가 어떤지 확인하고 수정해야 합니다. | ||
localStorage.setItem("authToken", token); // 토큰을 localStorage에 저장 | ||
|
||
// 로그인 성공 시 전역 상태를 업데이트합니다. | ||
dispatch(setLoginState()); | ||
}; | ||
|
||
const handleError = () => { | ||
console.log("Login Failed"); | ||
}; | ||
|
||
// One-tap 로그인 (선택적) | ||
useGoogleOneTapLogin({ | ||
onSuccess: handleSuccess, | ||
onError: handleError, | ||
}); | ||
|
||
return ( | ||
<GoogleOAuthProvider | ||
clientId=" | ||
690344785644-2oj84rcukd2rhu3o56gbq6rahap16m37.apps.googleusercontent.com" | ||
> | ||
<GoogleLogin onSuccess={handleSuccess} onError={handleError} useOneTap /> | ||
</GoogleOAuthProvider> | ||
); | ||
}; | ||
|
||
export default GoogleSignInComponent; | ||
|
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,23 +1,21 @@ | ||
import { createSlice } from '@reduxjs/toolkit'; | ||
import { createSlice } from "@reduxjs/toolkit"; | ||
|
||
const initialState: number = 0; | ||
|
||
const loginSlice = createSlice({ | ||
name: 'login', | ||
initialState: { | ||
memberId: 0, | ||
isLoggedIn: 1 | ||
}, | ||
name: "login", | ||
initialState: initialState, | ||
reducers: { | ||
setLoginState: (state, action) => { | ||
state.memberId = action.payload; | ||
state.isLoggedIn = 1; | ||
setLoginState: (state) => { | ||
state = 1; | ||
return state; | ||
}, | ||
setLogoutState: (state) => { | ||
state.memberId = 0; | ||
state.isLoggedIn = 0; | ||
state = 0; | ||
return state; | ||
}, | ||
|
||
} | ||
}, | ||
}); | ||
|
||
export const { setLoginState, setLogoutState} = loginSlice.actions; | ||
export default loginSlice.reducer; | ||
export const { setLoginState, setLogoutState } = loginSlice.actions; | ||
export const loginReducer = loginSlice.reducer; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.