icns-frontend/pages/api/auth/access-token.ts
2022-11-30 22:49:09 +09:00

19 lines
524 B
TypeScript

import type { NextApiRequest, NextApiResponse } from "next";
import { authClient } from "../../client/twitter";
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
try {
const { code, state } = req.query;
if (state !== process.env.TWITTER_AUTH_STATE) {
return res.status(500).send("State isn't matching");
}
const { token } = await authClient.requestAccessToken(code as string);
res.status(200).json(token);
} catch (error) {
console.log(error);
}
}