-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' of https://github.com/Neogasogaeseo/Naega-Web into…
… feat/#113
- Loading branch information
Showing
10 changed files
with
128 additions
and
16 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,11 @@ | ||
import { atom } from 'recoil'; | ||
|
||
export const kakaoAccessTokenState = atom<string>({ | ||
key: 'kakaoAccessTokenState', | ||
default: '', | ||
}); | ||
|
||
export const kakaoRefreshTokenState = atom<string>({ | ||
key: 'kakaoRefreshTokenState', | ||
default: '', | ||
}); |
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 |
---|---|---|
@@ -1,5 +1,39 @@ | ||
import { LoginUser } from './types/user'; | ||
import { publicAPI } from '../remote/base'; | ||
|
||
export interface LoginUserService { | ||
getUserInfo(token: string): Promise<LoginUser>; | ||
} | ||
|
||
export const postLogin = async ( | ||
kakaoToken: string, | ||
): Promise<{ user?: object; accesstoken: string; refreshtoken: string }> => { | ||
try { | ||
const response = await publicAPI.post({ | ||
url: `/auth/login`, | ||
data: { authenticationCode: kakaoToken, provider: 'kakao' }, | ||
}); | ||
if (response.status === 200) return response.data; | ||
else throw '로그인 실패'; | ||
} catch (e) { | ||
console.error(e); | ||
throw '로그인 실패'; | ||
} | ||
}; | ||
|
||
export const postJoin = async (joinData: FormData) => { | ||
try { | ||
const response = await publicAPI.post({ | ||
url: `/auth/register`, | ||
data: joinData, | ||
type: 'multipart', | ||
}); | ||
if (response.status === 200) { | ||
return response.data; | ||
} | ||
throw '회원가입 실패'; | ||
} catch (e) { | ||
console.error(e); | ||
throw '회원가입 실패'; | ||
} | ||
}; |
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
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
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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
const CLIENT_ID = `${process.env.REACT_APP_CLIENT_ID}`; | ||
const REDIRECT_URI = 'http://localhost:3000/oauth'; | ||
const REDIRECT_URI = 'http://localhost:3000/auth/kakao/callback'; | ||
|
||
export const KAKAO_AUTH_URL = `https://kauth.kakao.com/oauth/authorize?client_id=${CLIENT_ID}&redirect_uri=${REDIRECT_URI}&response_type=code`; |
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
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
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,31 @@ | ||
import { kakaoAccessTokenState, kakaoRefreshTokenState } from '@stores/kakao-auth'; | ||
import { useEffect } from 'react'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { useSetRecoilState } from 'recoil'; | ||
import { postLogin } from '@api/login-user'; | ||
import { useLoginUser } from '@hooks/useLoginUser'; | ||
|
||
const OAuthRedirectHandler = () => { | ||
const navigate = useNavigate(); | ||
const { setAccessToken } = useLoginUser(); | ||
const setKakaoAccessToken = useSetRecoilState(kakaoAccessTokenState); | ||
const setKakaoRefreshToken = useSetRecoilState(kakaoRefreshTokenState); | ||
|
||
useEffect(() => { | ||
const code = new URL(window.location.href).searchParams.get('code') ?? ''; //인가코드 | ||
postLogin(code).then((response) => { | ||
if (response.user) { | ||
setAccessToken(response.accesstoken); | ||
navigate('/home'); | ||
} else { | ||
setKakaoAccessToken(response.accesstoken); | ||
setKakaoRefreshToken(response.refreshtoken); | ||
navigate('/join'); | ||
} | ||
}); | ||
}, []); | ||
|
||
return <></>; | ||
}; | ||
|
||
export default OAuthRedirectHandler; |
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