Skip to content

Commit

Permalink
Feat: #38 서버에 jwt 토큰 요청, url 이동하는 함수 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
eve712 committed Jun 15, 2021
1 parent 9832bb7 commit 34207a2
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions FE/issue-tracker/src/components/login/getAccessToken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { TOKEN_URL } from '@const/var';

type Arg = {
isLogin: boolean;
setIsLogin: (state: boolean) => void;
code: string;
};

const fetchToken = async ({ isLogin, setIsLogin, code }: Arg) => {
if (isLogin) return;
try {
const response = await fetch(TOKEN_URL + code);
const { jwt } = await response.json();
localStorage.setItem('oauth_login', jwt);
setIsLogin(true);
window.location.href = '/issues';
} catch (error) {
console.error('getAccessToken Error');
}
};

export default fetchToken;

0 comments on commit 34207a2

Please sign in to comment.