Skip to content

Comments

update better-auth and graceful auth error#1279

Merged
MrgSub merged 2 commits intostagingfrom
06-10-update_better-auth_and_graceful_auth_error
Jun 10, 2025
Merged

update better-auth and graceful auth error#1279
MrgSub merged 2 commits intostagingfrom
06-10-update_better-auth_and_graceful_auth_error

Conversation

@ahmetskilinc
Copy link
Contributor

@ahmetskilinc ahmetskilinc commented Jun 10, 2025

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:

  • Added an error alert component on the login page that shows when the 'error' query parameter is present
  • Configured onAPIError in the auth config to redirect to the login page on authentication failures
  • Updated the better-auth dependency from 1.2.8 to 1.2.9

Type of Change

  • 🎨 UI/UX improvement

Areas Affected

  • User Interface/Experience
  • Authentication/Authorization

Summary by CodeRabbit

  • New Features

    • Added an alert message on the login page to inform users when a login attempt fails.
  • Chores

    • Updated the version of the authentication package to improve reliability.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 10, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The 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 better-auth package version in the workspace configuration. No public API or exported entity signatures are altered.

Changes

File(s) Change Summary
apps/mail/app/(auth)/login/login-client.tsx Adds conditional rendering of a warning alert for login errors based on the "error" query parameter.
apps/server/src/lib/auth.ts Adds onAPIError config to authentication, enabling centralized API error handling and redirection.
pnpm-workspace.yaml Updates better-auth package version from ^1.2.8 to ^1.2.9.

Poem

In the warren, errors now appear,
With orange alerts, the message is clear.
The server logs with a watchful eye,
And auth gets better—oh my!
With every hop, we debug and mend,
Until the login journey’s end.
🥕✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 02589be and 0d9e7c1.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is 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)
✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@ahmetskilinc ahmetskilinc marked this pull request as ready for review June 10, 2025 16:40
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between fc75ca6 and 02589be.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is 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:


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 onAPIError configuration 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

@MrgSub MrgSub force-pushed the 06-10-update_better-auth_and_graceful_auth_error branch from 02589be to 0d9e7c1 Compare June 10, 2025 20:51
Copy link
Collaborator

MrgSub commented Jun 10, 2025

Merge activity

  • Jun 10, 8:52 PM UTC: Graphite rebased this pull request as part of a merge.
  • Jun 10, 8:53 PM UTC: @MrgSub merged this pull request with Graphite.

@MrgSub MrgSub merged commit 85c29ea into staging Jun 10, 2025
2 of 3 checks passed
@MrgSub MrgSub deleted the 06-10-update_better-auth_and_graceful_auth_error branch June 10, 2025 20:53
@coderabbitai coderabbitai bot mentioned this pull request Aug 4, 2025
34 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants