Auth: Expose the per-request Better Auth instance to server routes
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 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 分鐘
- 30 天內合併 PR
- 200
環境準備
這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
voidzero-dev/void 的其他 Issue
-
難度 4/5 3-5 天 新手友好度 55/100
voidzero-dev/void#718 · 1 個 reaction ·
維護者通常 1 天內回覆
-
難度 4/5 3-5 天 新手友好度 48/100
voidzero-dev/void#717 ·
維護者通常 1 天內回覆
-
難度 5/5 一週以上 新手友好度 28/100
voidzero-dev/void#692 · 1 則留言 ·
維護者通常 1 天內回覆
-
難度 5/5 一週以上 新手友好度 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
-
unwrapDatabaseError masks real DB errors with TypeError: Cannot convert object to primitive value未關閉
難度 2/5 1-3 小時 新手友好度 74/100
NEARBuilders/everything-dev#798 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
vercel-labs/durable-harness#53 ·
維護者通常 1 天內回覆
-
[Bug]: Redesign tab bars ignore clicks on Linux: hidden chat layers keep window drag regions可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉
難度 2/5 1-3 小時 新手友好度 82/100
維護者通常 1 天內回覆
-
experiência: a doc manda subir para o Micro do Supabase, mas não diz que exige plano pago nem quanto custa可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉area/docs area/ui enhancement
難度 1/5 1-3 小時 新手友好度 88/100
melgarafael/DeskcommCRM#4098 ·
維護者通常 1 天內回覆
-
dependencies platform: ios
難度 1/5 1-3 小時 新手友好度 78/100
software-mansion/react-native-executorch#1617 ·
維護者通常 1 天內回覆