feat(core): add publicEndpoints plugin capability for well-known endpoints#7524
Conversation
|
@gustavovalverde is attempting to deploy a commit to the better-auth Team on Vercel. A member of the Team first needs to authorize it. |
@better-auth/api-key
better-auth
auth
@better-auth/core
@better-auth/drizzle-adapter
@better-auth/electron
@better-auth/expo
@better-auth/i18n
@better-auth/kysely-adapter
@better-auth/memory-adapter
@better-auth/mongo-adapter
@better-auth/oauth-provider
@better-auth/passkey
@better-auth/prisma-adapter
@better-auth/redis-storage
@better-auth/scim
@better-auth/sso
@better-auth/stripe
@better-auth/telemetry
@better-auth/test-utils
commit: |
There was a problem hiding this comment.
Pull request overview
This PR adds a publicEndpoints capability to the Better Auth plugin system, enabling plugins to register endpoints at the origin root (e.g., /.well-known/openid-configuration) instead of under the configured basePath. This is necessary for RFC 8414 / OIDC Discovery compliance which requires well-known endpoints at specific root-level paths.
Changes:
- Added
publicEndpointsfield toBetterAuthPlugintype for defining root-level endpoints - Implemented
publicRouterthat mounts at/and auto-routing logic in main handler for/.well-known/*paths - Exposed optional
publicHandlerandpublicApion auth object when plugins use public endpoints - Added conflict detection for public endpoints with proper error messaging
- Refactored context resolution into reusable function
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/core/src/types/plugin.ts | Added publicEndpoints optional field to BetterAuthPlugin type definition |
| packages/better-auth/src/types/auth.ts | Added optional publicHandler and publicApi fields to Auth type, imported publicRouter type |
| packages/better-auth/src/auth/base.ts | Implemented auto-routing for .well-known/* paths, added publicHandler initialization, refactored context resolution |
| packages/better-auth/src/api/to-auth-endpoints.ts | Enhanced response detection logic and added null check for hook results |
| packages/better-auth/src/api/index.ts | Added publicRouter function, enhanced conflict detection for public endpoints, refactored router creation |
| packages/better-auth/src/api/public-endpoints.test.ts | Comprehensive test suite (11 tests) covering public endpoint functionality |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
1e50cb0 to
71d8fd1
Compare
0d28aca to
1952da7
Compare
1952da7 to
737971a
Compare
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
737971a to
b56f307
Compare
b56f307 to
8f0116d
Compare
Summary
Adds
publicEndpointsplugin capability for RFC 8414 / OIDC Discovery compliance.This allows plugins to register endpoints at the origin root (e.g.,
/.well-known/openid-configuration) instead of under thebasePath(e.g.,/api/auth/.well-known/...).Important clarification: This does NOT mount Better Auth at root. Only
/.well-known/*paths are intercepted by the main handler and routed to the public router. All other endpoints remain at the configuredbasePath.Closes #7453
Changes
publicEndpointsfield toBetterAuthPlugintypepublicRouterthat mounts at/instead of basePath/.well-known/*in main handler to publicRouterpublicHandlerandpublicApion auth objectHow It Works
publicEndpointsalongside regularendpointshandlerautomatically routes/.well-known/*requests to the public routerpublicHandlerandpublicApiare only defined when plugins actually usepublicEndpointsExample Usage
Test Plan
Summary by cubic
Adds
publicEndpointsso plugins can serve well-known routes at the origin root (/.well-known/*) while keeping all other endpoints underbasePath. When used, the auth instance exposes a dedicated public router and API.New Features
publicEndpointsonBetterAuthPlugin; newpublicRoutermounts at/, and the main handler auto-routes/.well-known/*.publicHandlerandpublicApiare exposed only when at least one plugin definespublicEndpoints.publicEndpoints,publicHandler, andpublicApi.Bug Fixes
baseURL(recomputes trusted origins/providers and cookies; resolves base URL on first request for static configs).Written for commit 8f0116d. Summary will update on new commits.