Skip to content

Commit

Permalink
feat: redirect to github auth (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
aahna-ashina committed Sep 22, 2023
1 parent 4a43df4 commit f41d5a2
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 20 deletions.
49 changes: 49 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"eslint": "8.38.0",
"eslint-config-next": "13.3.0",
"next": "13.3.0",
"next-connect": "^0.13.0",
"papaparse": "^5.4.1",
"passport": "^0.6.0",
"passport-github2": "^0.1.12",
Expand Down
30 changes: 10 additions & 20 deletions src/pages/api/[passportId]/auth/github.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
// import nc, { createEdgeRouter } from "next-connect"
import { NextFetchEvent, NextRequest } from "next/server"
import nc from "next-connect"
const passport = require('passport')
const GitHubStrategy = require('passport-github2').Strategy

// Configure strategy
const callbackBaseUrl = process.env['GITHUB_CALLBACK_BASE_URL']
console.info('callbackBaseUrl:', callbackBaseUrl)

const callbackUrl = `${callbackBaseUrl}/api/233/auth/github-callback` // TODO: get [passportId]
console.info('callbackUrl:', callbackUrl)

// const router = createEdgeRouter<NextRequest, NextFetchEvent>()
// router.use(async (request, event, next) => {
// // logging request example
// console.log(`${request.method} ${request.url}`);
// return next();
// });

// Configure strategy
passport.use(new GitHubStrategy(
{
clientID: process.env['GITHUB_CLIENT_ID'],
Expand All @@ -33,12 +23,12 @@ passport.use(new GitHubStrategy(
}
))

// // Redirect to GitHub authentication
// const handler = nc()
// .get(
// passport.authenticate('github', {
// scope: ['user:email']
// })
// )
// Redirect to GitHub authentication
const handler = nc()
.get(
passport.authenticate('github', {
scope: ['user:email']
})
)

// export default handler
export default handler

0 comments on commit f41d5a2

Please sign in to comment.