update better-auth and graceful auth error#1279
Conversation
|
Caution Review failedThe pull request is closed. WalkthroughThe changes introduce error handling UI in the mail app's login client, add centralized API error handling configuration to the server's authentication setup, and update the Changes
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (3)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
apps/mail/app/(auth)/login/login-client.tsx (1)
141-146: Consider improving error state management.The error alert implementation is well-designed and user-friendly. However, the error state persists until the URL changes, which could lead to stale error messages being displayed.
Consider adding automatic error clearing or a dismiss button:
- const [error, _] = useQueryState('error'); + const [error, setError] = useQueryState('error');Then add a dismiss handler to the Alert:
{error && ( - <Alert variant="default" className="border-orange-500/40 bg-orange-500/10"> + <Alert variant="default" className="border-orange-500/40 bg-orange-500/10"> + <button + onClick={() => setError(null)} + className="absolute right-2 top-2 text-orange-400 hover:text-orange-300" + > + × + </button> <AlertTitle className="text-orange-400">Error</AlertTitle> <AlertDescription>Failed to log you in. Please try again.</AlertDescription> </Alert> )}
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (3)
apps/mail/app/(auth)/login/login-client.tsx(3 hunks)apps/server/src/lib/auth.ts(1 hunks)pnpm-workspace.yaml(1 hunks)
🔇 Additional comments (3)
pnpm-workspace.yaml (1)
7-7:Details
❓ Verification inconclusive
Dependency update looks good.
The better-auth version bump from ^1.2.8 to ^1.2.9 aligns with the authentication error handling improvements in this PR.
Please verify the changelog for better-auth 1.2.9 to ensure compatibility:
🌐 Web query:
What are the changes in better-auth version 1.2.9 compared to 1.2.8?💡 Result:
Better Auth version 1.2.9 is currently in beta, with several beta releases already available. Based on the release notes, here are the key changes and improvements from version 1.2.8 to the upcoming 1.2.9 release:
New Features
- Custom Paths: An option to modify and map API paths has been added, allowing more flexibility in routing configuration[5]
- Promise Support for Custom User Info Claims: This enhancement improves the flexibility of handling user information[5]
- Bun SQLite Support: Native support for Bun SQLite has been added by default[5]
- MCP Plugin: A new MCP (Multi-Cloud Provider) plugin has been integrated into the library[5]
Bug Fixes
- Token Refresh: Fixed an issue where tokens would be unnecessarily refreshed when providers don't return refresh tokens[5]
- Prisma Schema Requirements: Removed the requirement for Prisma schema during development with Bun[5]
- SSR Handling: Improved SSR handling in useAuthQuery to prevent hydration issues[5]
- URL Encoding: Fixed issues with encoded callbackURL[5]
- User Filtering: Added support for "contains" filter for users in admin interface[5]
- Microsoft Entra Integration: Fixed token refresh scope for Microsoft Entra authentication[5]
- Apple Authentication: Response type is now set to idToken code to get full user profile data[5]
- Admin Impersonation: Fixed cookie prefix handling for impersonate admin cookies[5]
Other Improvements
The beta versions show ongoing development, with v1.2.9-beta.6 being the most recent release as of June 4, 2025[5]. Some users have reported issues with the update, such as schema-related problems where "member" and "pending" references from the organization plugin are not being properly defined after migration[9].
The full stable release of version 1.2.9 is expected to include all these improvements and possibly additional fixes based on feedback from the beta testing period. If you're planning to upgrade, be aware that some schema migrations may be required, and it's advisable to test the upgrade in a development environment first.
Citations:
- 1: https://www.better-auth.com/changelogs
- 2: https://github.com/better-auth/better-auth
- 3: https://www.npmjs.com/package/better-auth
- 4: https://security.snyk.io/package/npm/better-auth/1.2.9-beta.1
- 5: https://github.com/better-auth/better-auth/releases
- 6: https://borgbackup.readthedocs.io/en/1.2-maint/changes.html
- 7: https://auth0.com/changelog
- 8: https://www.youtube.com/watch?v=w07F5vZbLTg
- 9: https://www.answeroverflow.com/c/1288403910284935179
- 10: https://docs.couchdb.org/en/stable/api/server/common.html
Approve dependency bump—but verify 1.2.9 beta compatibility
The update to better-auth@^1.2.9 introduces new features and bug fixes but is still in beta. Please ensure:
- Testing in a development environment before promoting to production
- Running existing auth flows (SSR/SSG) to catch any hydration issues in useAuthQuery
- Verifying any required schema migrations for the organization plugin (“member”/“pending” references)
- Checking token refresh, callbackURL encoding, and Microsoft Entra/Apple Auth flows for regressions
- Confirming Bun SQLite support and the new MCP plugin integrate cleanly
- Reviewing custom path mapping and promise-based user info claims if you adopt them
Once these verifications pass, you can safely merge.
apps/server/src/lib/auth.ts (1)
286-292: Well-implemented centralized error handling.The
onAPIErrorconfiguration provides a clean, centralized approach to handling authentication errors. The implementation correctly logs errors for debugging while redirecting users to the login page where the enhanced UI can display appropriate error messages.apps/mail/app/(auth)/login/login-client.tsx (1)
1-1: Good integration of error state management.The addition of Alert components and useQueryState for error handling creates a clean integration with the server-side error redirection. The error state is properly read from URL parameters as expected from the backend configuration.
Also applies to: 10-10, 73-73
02589be to
0d9e7c1
Compare

Improved Authentication Error Handling
Description
This PR enhances the login experience by adding proper error handling for authentication failures. It adds an error alert component to the login page that displays when authentication fails, and configures the auth system to redirect users back to the login page with an error parameter when authentication errors occur.
The changes include:
onAPIErrorin the auth config to redirect to the login page on authentication failuresType of Change
Areas Affected
Summary by CodeRabbit
New Features
Chores