From 092afbdbbf3fe433c6547bbc698e45b1a0bc3e2e Mon Sep 17 00:00:00 2001 From: Omar White Date: Sun, 31 Mar 2024 20:19:20 -0400 Subject: [PATCH] Revert "goes back to accessToken.token" This reverts commit ebe9a50ea8f5fa4c81d088744013c255d18e9dd1. --- src/pages/api/callback.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/pages/api/callback.ts diff --git a/src/pages/api/callback.ts b/src/pages/api/callback.ts new file mode 100644 index 0000000..84c286b --- /dev/null +++ b/src/pages/api/callback.ts @@ -0,0 +1,31 @@ +import type { NextApiRequest, NextApiResponse } from 'next'; +import { renderBody, createClient } from '@/lib/oauth2'; + +export default async function handler( + req: NextApiRequest, + res: NextApiResponse +) { + const code = req.query.code; + const { host } = req.headers; + + const oauthClient = createClient(); + + try { + const accessToken = await oauthClient.getToken({ + code, + redirect_uri: `https://${host}/api/callback`, + scope: `repo,user`, + }); + + const { token } = oauthClient.createToken(accessToken); + + res.status(200).send( + renderBody('success', { + token: token.access_token, + provider: 'github', + }) + ); + } catch (e) { + res.status(200).send(renderBody('error', e)); + } +}