Skip to content

Commit

Permalink
Feat: #38 디코드된 로그인 정보 로컬스토리지에 저장
Browse files Browse the repository at this point in the history
  • Loading branch information
eve712 committed Jun 18, 2021
1 parent a29d0f2 commit c475000
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion FE/issue-tracker/src/components/login/getAccessToken.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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) {
Expand Down

0 comments on commit c475000

Please sign in to comment.