2022-11-30 09:58:19 +00:00
|
|
|
import type { NextApiRequest, NextApiResponse } from "next";
|
|
|
|
import { authClient } from "../../client/twitter";
|
|
|
|
|
|
|
|
export default function handler(req: NextApiRequest, res: NextApiResponse) {
|
2022-11-30 13:49:09 +00:00
|
|
|
if (
|
|
|
|
!process.env.TWITTER_AUTH_STATE ||
|
|
|
|
!process.env.TWITTER_AUTH_CODE_CHALLENGE
|
|
|
|
) {
|
2022-11-30 09:58:19 +00:00
|
|
|
return res.status(500).send("No state or code_challenge");
|
|
|
|
}
|
|
|
|
|
|
|
|
const authUrl = authClient.generateAuthURL({
|
2022-11-30 13:49:09 +00:00
|
|
|
state: process.env.TWITTER_AUTH_STATE,
|
|
|
|
code_challenge: process.env.TWITTER_AUTH_CODE_CHALLENGE,
|
2022-11-30 09:58:19 +00:00
|
|
|
code_challenge_method: "plain",
|
|
|
|
});
|
2022-11-30 13:49:09 +00:00
|
|
|
res.status(200).json({ authUrl });
|
2022-11-30 09:58:19 +00:00
|
|
|
}
|