feat: migrate from NextAuth v5 to Better Auth#44
Merged
chriskehayias merged 2 commits intomainfrom Feb 20, 2026
Merged
Conversation
Replace NextAuth v5 (beta) with Better Auth for OAuth authentication against Ministry Platform's OIDC endpoints. Key changes: - New auth config (src/lib/auth.ts) with genericOAuth, customSession, and nextCookies plugins - New auth client (src/lib/auth-client.ts) for client-side hooks - Route handler renamed from [...nextauth] to [...all] - Proxy uses getSessionCookie() instead of getToken() from next-auth/jwt - Session uses JWT cookie cache (stateless, no database) - OAuth sub claim stored as user.userGuid via additionalFields + mapProfileToUser (Better Auth generates its own internal user.id) - customSession only does lightweight name splitting (no API calls) - User profile loading moved to client-side UserProvider - Server actions use userGuid for MP API lookups - Custom RP-initiated OIDC logout preserved - Auth reference doc added at .claude/references/auth.md - Error propagation improved in server actions and HTTP client - Pre-existing const reassignment bug fixed in generate-types.ts Removed: - src/auth.ts (NextAuth config) - src/types/next-auth.d.ts (NextAuth type augmentation) - src/lib/providers/ministry-platform/auth/auth-provider.ts Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
user.userGuidviaadditionalFields+mapProfileToUser, since Better Auth generates its own internaluser.id.Changes by area
New files:
src/lib/auth.ts— Better Auth server config (genericOAuth, customSession, nextCookies plugins)src/lib/auth-client.ts— Client-side auth clientsrc/app/api/auth/[...all]/route.ts— Better Auth route handler.claude/references/auth.md— Detailed auth reference documentationModified (auth migration):
src/proxy.ts—getSessionCookie()replacesgetToken()from next-auth/jwtsrc/app/providers.tsx— RemovedSessionProvider, simplified toUserProvideronlysrc/app/signin/page.tsx— UsesauthClient.signIn.oauth2()/authClient.getSession()src/contexts/user-context.tsx— UsesauthClient.useSession(), readsuserGuidfor profile loadingsrc/contexts/session-context.tsx— Simplified touseAppSession()wrappersrc/components/layout/auth-wrapper.tsx— Usesauth.api.getSession()src/components/user-menu/actions.ts— Custom OIDC logout viaauth.api.signOut()contact-logs,contact-lookup-details,user-tools-debug) — UseuserGuidfor MP lookups, improved error propagationsrc/lib/providers/ministry-platform/utils/http-client.ts— GET errors now include response body.env.example,CLAUDE.md,README.md— Updated for Better AuthDeleted:
src/auth.ts(NextAuth config)src/types/next-auth.d.ts(NextAuth type augmentation)src/lib/providers/ministry-platform/auth/auth-provider.ts(NextAuth-specific provider)Tests rewritten:
src/auth.test.ts— Tests customSession name splitting, userGuid mapping, OAuth configsrc/proxy.test.ts— Mocksbetter-auth/cookiesinstead ofnext-auth/jwtTest plan
npm run build)npm run test:run) — 137 tests across 6 filesuser.userGuidis populated after login (check session in browser devtools)/api/auth/oauth2/callback/ministry-platformGenerated with Claude Code