diff --git a/FE/issue-tracker/src/components/login/getAccessToken.ts b/FE/issue-tracker/src/components/login/getAccessToken.ts index d2665323d..560b71f53 100644 --- a/FE/issue-tracker/src/components/login/getAccessToken.ts +++ b/FE/issue-tracker/src/components/login/getAccessToken.ts @@ -1,5 +1,23 @@ +import jwt_decode from 'jwt-decode'; import { TOKEN_URL } from '@const/var'; +type decodedType = { + avatar_url: string; + name: string; + id: number; + iss: string; +}; + +const getDecodedOauthToken = (jwt: string) => { + const decoded: decodedType = jwt_decode(jwt); + const loginInfo = { + avatar_url: decoded.avatar_url, + name: decoded.name, + id: decoded.id, + }; + return loginInfo; +}; + type Arg = { isLogin: boolean; setIsLogin: (state: boolean) => void; @@ -11,7 +29,9 @@ const fetchToken = async ({ isLogin, setIsLogin, code }: Arg) => { try { const response = await fetch(TOKEN_URL + code); const { jwt } = await response.json(); - localStorage.setItem('oauth_login', jwt); + const decodedOauthToken = getDecodedOauthToken(jwt); + localStorage.setItem('oauth_login_token', jwt); + localStorage.setItem('login_info', JSON.stringify(decodedOauthToken)); setIsLogin(true); window.location.href = '/issues'; } catch (error) {