diff --git a/.changeset/two-crabs-speak.md b/.changeset/two-crabs-speak.md new file mode 100644 index 00000000..3d345f89 --- /dev/null +++ b/.changeset/two-crabs-speak.md @@ -0,0 +1,5 @@ +--- +'@hono/oauth-providers': patch +--- + +ensure redirect to original URL for GitHub apps diff --git a/packages/oauth-providers/src/providers/github/githubAuth.ts b/packages/oauth-providers/src/providers/github/githubAuth.ts index fbae6ee4..665da022 100644 --- a/packages/oauth-providers/src/providers/github/githubAuth.ts +++ b/packages/oauth-providers/src/providers/github/githubAuth.ts @@ -40,7 +40,11 @@ export function githubAuth(options: { path: '/', // secure: true, }) - return c.redirect(auth.redirect()) + + // OAuth apps can't have multiple callback URLs, but GitHub Apps can. + // As such, we want to make sure we call back to the same location + // for GitHub apps and not the first configured callbackURL in the app config. + return c.redirect(auth.redirect().concat(options.oauthApp ? '' : `&redirect_uri=${c.req.url}`)) } // Retrieve user data from github