icns-frontend/pages/api/auth/access-token.ts

19 lines
528 B
TypeScript
Raw Normal View History

2022-11-30 09:58:19 +00:00
import type { NextApiRequest, NextApiResponse } from "next";
2022-11-30 14:55:17 +00:00
import { authClient } from "../../../client/twitter";
2022-11-30 09:58:19 +00:00
export default async function handler(
req: NextApiRequest,
2022-11-30 14:55:17 +00:00
res: NextApiResponse,
2022-11-30 09:58:19 +00:00
) {
try {
const { code, state } = req.query;
2022-11-30 13:49:09 +00:00
if (state !== process.env.TWITTER_AUTH_STATE) {
2022-11-30 09:58:19 +00:00
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);
}
}