forked from LaconicNetwork/icns-frontend
19 lines
511 B
TypeScript
19 lines
511 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.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);
|
||
|
}
|
||
|
}
|