-
Notifications
You must be signed in to change notification settings - Fork 4
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 #25 from dongbin420/feat/log-out
feat/쿠키다시 설정하고 로그아웃 구현
- Loading branch information
Showing
4 changed files
with
43 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { removeCookie } from '../utils/cookie'; | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
const LogoutButton = () => { | ||
const navigate = useNavigate(); | ||
|
||
const handleLogout = () => { | ||
removeCookie('jwtToken'); | ||
window.alert('로그아웃 되었습니다.'); | ||
navigate('/'); | ||
}; | ||
|
||
return ( | ||
<button className="mt-2 w-96 rounded bg-mainblack px-1 py-2 text-white" onClick={handleLogout}> | ||
로그아웃 | ||
</button> | ||
); | ||
}; | ||
|
||
export default LogoutButton; |
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,11 @@ | ||
import { setCookie } from '../cookie'; | ||
|
||
export const saveTokenFromResponse = (response: Response) => { | ||
const authHeader = response.headers.get('Authorization'); | ||
|
||
if (authHeader && authHeader.startsWith('Bearer ')) { | ||
const token = authHeader.substring(7); | ||
console.log('추출된 JWT 토큰:', token); | ||
setCookie('jwtToken', token); | ||
} | ||
}; |