From c475000bcfe4a8796c33278445d475b6859086a3 Mon Sep 17 00:00:00 2001 From: eve712 <62237639+eve712@users.noreply.github.com> Date: Sat, 19 Jun 2021 05:50:30 +0900 Subject: [PATCH] =?UTF-8?q?Feat:=20#38=20=EB=94=94=EC=BD=94=EB=93=9C?= =?UTF-8?q?=EB=90=9C=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=EB=A1=9C=EC=BB=AC=EC=8A=A4=ED=86=A0=EB=A6=AC=EC=A7=80=EC=97=90?= =?UTF-8?q?=20=EC=A0=80=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/login/getAccessToken.ts | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) 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) {