-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: #38 서버에 jwt 토큰 요청, url 이동하는 함수 작성
- Loading branch information
Showing
1 changed file
with
22 additions
and
0 deletions.
There are no files selected for viewing
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,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; |