-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1421f12
commit 5e1d4a3
Showing
8 changed files
with
114 additions
and
30 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
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,32 @@ | ||
import React, { useCallback } from 'react'; | ||
import { setCookie } from 'react-use-cookie'; | ||
import { jwtDecode } from 'jwt-decode'; | ||
import { Profile, Logout } from './style'; | ||
import { getToken } from 'utils/getToken'; | ||
|
||
function UserProfile() { | ||
const token = getToken(); | ||
const payload = jwtDecode(token); | ||
|
||
const onLogout = useCallback(() => { | ||
setCookie('zoommentToken', '', { days: -1 }); | ||
|
||
const url = new URL(window.location.href); | ||
|
||
if (url.searchParams.has('zoommentToken')) { | ||
url.searchParams.delete('zoommentToken'); | ||
} | ||
|
||
window.location.href = url.toString(); | ||
}, []); | ||
|
||
return ( | ||
payload && ( | ||
<Profile> | ||
{payload.email} (<Logout onClick={onLogout}>logout</Logout>) | ||
</Profile> | ||
) | ||
); | ||
} | ||
|
||
export default UserProfile; |
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,21 @@ | ||
import styled from 'styled-components'; | ||
|
||
export const Profile = styled.div` | ||
width: 100%; | ||
line-height: 1; | ||
font-size: 11px; | ||
padding: 10px 10px; | ||
font-weight: 700; | ||
color: ${props => props.theme.textColor}; | ||
display: flex; | ||
align-items: center; | ||
`; | ||
|
||
export const Logout = styled.span` | ||
line-height: 1; | ||
font-size: 11px; | ||
font-weight: 700; | ||
color: #e33725; | ||
text-decoration: underline; | ||
cursor: pointer; | ||
`; |
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,9 @@ | ||
import { getCookie } from 'react-use-cookie'; | ||
|
||
export const getToken = () => { | ||
const searchParams = new URL(window.location.href).searchParams; | ||
const zoommentToken = searchParams.get('zoommentToken'); | ||
const token = zoommentToken || getCookie('zoommentToken'); | ||
|
||
return token; | ||
}; |