Skip to main content
Go to Latest
File

oauth2

Github

Note: github_client_id and github_client_secret need to be set as environment variables.

api/oauth2/github/login.ts

import { Get, v } from 'darkflare'
import { Github } from 'darkflare/oauth2'

Get({}, async c => {
  Github.redirect(c) // only 'read:user' scope

  // alternatively, you can specify a custom set of scopes:
  Github.redirect(c, ['read:user', 'user:email'])
})

api/oauth2/github/callback.ts

import { Get, v } from 'darkflare'
import { Github } from 'darkflare/oauth2'

Get({
  query: v.Object({
    code: v.String()
  })
}, async c => {
  const token = await Github.getAccessToken(c)
  const user = await Github.getUser(token)

  return `Welcome, ${user.name}!`
})