Auth: Expose the per-request Better Auth instance to server routes
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 18/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- typescript
- 領域
- api, authentication
調査の方向性
Start with the void/auth exports getUser, getSession and requireAuth, and with runVoidAuthMiddleware, which stores the per-request Better Auth instance under the Hono context key __voidAuth. The issue asks for a supported accessor such as getAuth(c) plus a decision on whether /.well-known/ OAuth discovery paths should be forwarded. Done means the maintainers have chosen an approach and a route can get the instance without the private key.
索引モデルが issue の本文から書いたものです。
説明
Summary
I'd like a supported way to get the Better Auth instance that Void creates for the
current request, so that server routes can pass it to Better Auth plugin helpers.
Today void/auth exports getUser(), getSession() and requireAuth(), which cover
user and session checks, but it doesn't export the instance itself.
The only way I've found to reach the instance is to read the internal Hono context key "__voidAuth",
which isn't documented and could change in any release.
Use case
My app is an MCP server that uses Better Auth's OAuth provider, with the jwt() and
mcp() plugins from @better-auth/mcp. Several pieces of that setup need the
Better Auth instance as an argument, so I can't write them with the current
void/auth exports:
- The MCP route wraps its handler with
requireMcpAuth(auth, handler, options)from
@better-auth/mcp, which checks the OAuth access token on each request. - MCP clients fetch OAuth discovery documents at the site root, e.g.
/.well-known/oauth-protected-resource/mcpand
/.well-known/oauth-authorization-server/api/auth. Void only forwards
/api/auth/*to Better Auth, so I added a route underroutes/.well-known/that
passes these requests toauth.handler(request). - My sign-in and consent page loaders use
auth.$contextto count users through
the database adapter, because the app allows only one account.
Current workaround
I read the instance from the Hono context in one helper function, and every route
calls that helper:
import type { Context } from "hono";
import type { betterAuth } from "better-auth";
type AuthInstance = ReturnType<typeof betterAuth>;
export function getAuthInstance(c: Context): AuthInstance {
const auth = c.get("__voidAuth") as AuthInstance | undefined;
if (!auth) {
throw new Error('Void did not provide a Better Auth instance at "__voidAuth".');
}
return auth;
}
The workaround depends on runVoidAuthMiddleware, which calls
c.set("__voidAuth", auth) in Void's Better Auth runtime code. I checked that the key
is the same in 1.2.1 and 1.4.0. If the key is renamed, my MCP endpoint, the discovery
documents and the sign-in page all stop working, and the type cast means nothing
catches it at build time.
Proposal
I'd like void/auth to export a function that returns the current request's
instance, with the same request handling as requireAuth(c). For example:
import { getAuth } from "void/auth";
export const POST = defineHandler(async (c) => {
const auth = getAuth(c);
return requireMcpAuth(auth, handleMcpRequest, { resource })(c.req.raw);
});
I'd also like the return type to include the plugins from auth.ts, the same way
AuthUser and AuthSession now include plugin fields in 1.4.0, so that the
endpoints plugins add under auth.api type check without a cast.
If Void prefers not to expose the instance, I could instead use built-in support for
the two OAuth needs above. That would mean forwarding the /.well-known/ OAuth
discovery paths to Better Auth when the mcp() or oauthProvider() plugin is
enabled, and adding a documented way to protect a route with an OAuth access token.
Environment
- void 1.4.0, @void/svelte 1.4.0
- better-auth 1.7.12, @better-auth/mcp 1.7.12
- Native Cloudflare deploy (Workers and D1)
Disclaimers
Written by Claude Opus 5, reviewed and edited by Humans.
- 主要言語
- TypeScript
- スター
- 627
- フォーク
- 66
- 平均マージ
- 14時間 17分
- マージ済み PR(30日)
- 200
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
voidzero-dev/void のほかの issue
-
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
voidzero-dev/void#718 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
voidzero-dev/void#717 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 28/100
voidzero-dev/void#692 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 30/100
voidzero-dev/void#689 ·
メンテナーはふだん 1 日以内に返信
-
`withValidator({ body })` rejects the multipart bodies that `useForm` and `action()` send for filesオープン
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
voidzero-dev/void#679 ·
メンテナーはふだん 1 日以内に返信
voidzero-dev/void の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
appandflow/stim#5258 ·
メンテナーはふだん 1 日以内に返信
-
area/docs framework/hugo help wanted language/markdown
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
メンテナーはふだん 1 日以内に返信
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
難易度 1/5 1時間未満 初心者へのやさしさ 68/100
lingdojo/kana-dojo#33660 · コメント 1 件 · リアクション 5 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
drizzle-team/drizzle-orm#6639 ·
メンテナーはふだん 4 日以内に返信
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100