Skip to content

Commit

Permalink
Revert "goes back to accessToken.token"
Browse files Browse the repository at this point in the history
This reverts commit ebe9a50.
  • Loading branch information
Omar White committed Apr 1, 2024
1 parent 106206f commit 092afbd
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/pages/api/callback.ts
Original file line number Diff line number Diff line change
@@ -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));
}
}

0 comments on commit 092afbd

Please sign in to comment.