2022-11-30 09:58:19 +00:00
|
|
|
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;
|
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);
|
|
|
|
}
|
|
|
|
}
|