kakaots 추가
This commit is contained in:
@@ -0,0 +1,33 @@
|
|||||||
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||||
|
|
||||||
|
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||||
|
if (req.method !== 'POST') {
|
||||||
|
return res.status(405).json({ message: 'Method Not Allowed' });
|
||||||
|
}
|
||||||
|
|
||||||
|
const { code } = req.body;
|
||||||
|
|
||||||
|
if (!code) {
|
||||||
|
return res.status(400).json({ message: 'Authorization code is missing' });
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const tokenResponse = await fetch('https://kauth.kakao.com/oauth/token', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||||
|
body: new URLSearchParams({
|
||||||
|
grant_type: 'authorization_code',
|
||||||
|
client_id: process.env.KAKAO_CLIENT_ID!,
|
||||||
|
redirect_uri: process.env.KAKAO_REDIRECT_URI!,
|
||||||
|
code,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!tokenResponse.ok) throw new Error('Failed to fetch access token');
|
||||||
|
const tokenData = await tokenResponse.json();
|
||||||
|
|
||||||
|
res.status(200).json({ message: '카카오 로그인 성공', token: tokenData });
|
||||||
|
} catch (err) {
|
||||||
|
res.status(500).json({ message: (err as Error).message });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user