icns-frontend/pages/api/auth/index.ts

19 lines
590 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 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
}