-
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 #99
- Loading branch information
김병현
authored and
김병현
committed
Sep 15, 2023
1 parent
211d957
commit c250994
Showing
5 changed files
with
75 additions
and
94 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
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// TokenHandler.tsx | ||
|
||
import React, { useEffect } from 'react'; | ||
import { useDispatch } from "react-redux"; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { setLoginState } from "../../reducer/member/loginSlice"; | ||
|
||
const TokenHandler: React.FC = () => { | ||
const dispatch = useDispatch(); | ||
const navigate = useNavigate(); | ||
|
||
useEffect(() => { | ||
const urlParams = new URLSearchParams(window.location.search); | ||
const accessToken = urlParams.get("access_token"); | ||
const refreshToken = urlParams.get("refresh_token"); | ||
|
||
if (accessToken && refreshToken) { | ||
localStorage.setItem("Authorization", `Bearer ${accessToken}`); | ||
localStorage.setItem("Refresh-token", refreshToken); | ||
dispatch(setLoginState()); | ||
navigate('/'); | ||
} | ||
}, [dispatch, navigate]); | ||
|
||
return null; // 이 컴포넌트는 UI를 렌더링하지 않습니다. | ||
}; | ||
|
||
export default TokenHandler; |
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