Skip to content

Commit 5ea1606

Browse files
committed
✨ feat(#165): 네이버 액세스 토큰 서버로부터 받아오기
1 parent d143fa4 commit 5ea1606

2 files changed

Lines changed: 23 additions & 18 deletions

File tree

src/api/login/oauth.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Provider } from '@/types/login';
2+
import client from '../client';
3+
4+
export const getOauthAccessToken = async (
5+
provider: Provider,
6+
code: string,
7+
state: string
8+
) => {
9+
const response = await client.post(`/api/v1/auth/token/${provider}`, {
10+
code: code,
11+
state: state
12+
});
13+
const { accessToken } = response.data;
14+
return accessToken;
15+
};

src/app/login/auth/page.tsx

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use client';
22

3+
import { getOauthAccessToken } from '@/api/login/oauth';
34
import { login } from '@/api/login/user';
45
import Loader from '@/components/common/Loader';
56
import { signupState } from '@/recoil/signupStore';
@@ -43,6 +44,7 @@ const Auth = () => {
4344
const AUTHORIZATION_CODE = new URL(window.location.href).searchParams.get(
4445
'code'
4546
);
47+
const STATE = new URL(window.location.href).searchParams.get('state');
4648

4749
const TYPE = new URL(window.location.href).searchParams.get('type');
4850

@@ -103,24 +105,12 @@ const Auth = () => {
103105
break;
104106
case 'naver':
105107
try {
106-
// 백엔드 서버로부터 요청해서 받아오는 방식으로 변경하기
107-
// const body = new URLSearchParams({
108-
// grant_type: 'authorization_code',
109-
// client_id: process.env.NEXT_PUBLIC_NAVER_CLIENT_ID!,
110-
// client_secret: process.env.NEXT_PUBLIC_NAVER_CLIENT_SECRET!,
111-
// redirect_uri: absoluteUrl,
112-
// code: AUTHORIZATION_CODE,
113-
// });
114-
// const response = await axios.post(
115-
// 'https://nid.naver.com/oauth2.0/token',
116-
// body.toString(),
117-
// {
118-
// headers: {
119-
// 'Content-Type': 'application/x-www-form-urlencoded'
120-
// }
121-
// }
122-
// );
123-
// setOauthAccessToken(response.data.access_token);
108+
const response = await getOauthAccessToken(
109+
'NAVER' as Provider,
110+
AUTHORIZATION_CODE,
111+
STATE
112+
);
113+
setOauthAccessToken(response);
124114
} catch (error) {
125115
console.error('Unsupported OAuth type:', type);
126116
clearLetterUrl();

0 commit comments

Comments
 (0)