Skip to content

Commit

Permalink
fix: origin
Browse files Browse the repository at this point in the history
  • Loading branch information
stagas committed Oct 3, 2024
1 parent 175f5c7 commit 5666304
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions api/routes/oauth/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ export function mount(app: Router) {
} = env

app.get('/oauth/github', [async ctx => {
const origin =
ctx.request.headers.get('origin') ??
ctx.request.headers.get('referer')

const cb = OAuthCallback.parse(Object.fromEntries(ctx.url.searchParams.entries()))
if ('error' in cb) throw new RouteError(401, cb.error_description)

Expand Down Expand Up @@ -85,7 +89,7 @@ export function mount(app: Router) {
// user has already registered
if (userByEmail?.oauthGithub) {
await loginUser(ctx, userByEmail.nick)
const url = new URL(`${env.WEB_URL}/oauth/complete`)
const url = new URL(`${origin}/oauth/complete`)
url.searchParams.set('redirect_to', redirect_to)
const res = ctx.redirect(302, url.href)
return res
Expand All @@ -107,7 +111,7 @@ export function mount(app: Router) {
})

// redirect user to register
const url = new URL(`${env.WEB_URL}/oauth/register`)
const url = new URL(`${origin}/oauth/register`)
url.searchParams.set('id', id)
const res = ctx.redirect(302, url.href)

Expand Down

0 comments on commit 5666304

Please sign in to comment.