Redirect User to Reconnect if credentials become invalid#945
Conversation
Upgraded `drizzle-kit` to version 0.31.1 for improved functionality. Updated the schema to refine token fields and added logic to handle invalid tokens by nullifying them and redirecting users to reconnect. Enhanced connections API to identify and return disconnected connections for better user experience.
This migration allows the "access_token" column in the "mail0_connection" table to accept null values. Updated meta files reflect this schema change, including the snapshot and migration journal.
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThis update introduces the ability to detect and handle disconnected email account connections in the UI, including a "Reconnect" feature. It adds an AI-powered email subject generation function, updates localization and error handling, and modifies the database schema and API to support nullable access tokens and track disconnected states. Minor UI and code improvements are also included. Changes
Sequence Diagram(s)1. Disconnected Connection Handling and Reconnect FlowsequenceDiagram
participant User
participant UI
participant API
participant AuthClient
User->>UI: Visit Connections Settings
UI->>API: Fetch connections list
API-->>UI: Return connections + disconnectedIds
UI->>User: Show "Disconnected" badge and "Reconnect" button
User->>UI: Click "Reconnect"
UI->>AuthClient: linkSocial(providerId, callbackUrl)
AuthClient-->>UI: Reconnection flow (OAuth, etc.)
UI->>API: Refetch connections
2. AI-powered Email Subject GenerationsequenceDiagram
participant User
participant EmailComposer
participant API
User->>EmailComposer: Click "Generate Subject"
EmailComposer->>API: generateEmailSubject(message)
API-->>EmailComposer: Return generated subject
EmailComposer->>User: Populate subject input with AI-generated subject
Suggested reviewers
Poem
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 (
|
829f9f6 to
f01a54e
Compare
There was a problem hiding this comment.
Caution
Inline review comments failed to post. This is likely due to GitHub's limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.
Actionable comments posted: 1
🛑 Comments failed to post (1)
apps/mail/components/create/email-composer.tsx (1)
361-366: 🛠️ Refactor suggestion
Consider adding error handling to the subject generation function.
The function handles the happy path well but doesn't have explicit error handling unlike other similar functions in this component.
const handleGenerateSubject = async () => { + try { setIsGeneratingSubject(true); const { subject } = await generateEmailSubject({ message: editor.getText() }); setValue('subject', subject); + } catch (error) { + console.error('Error generating subject:', error); + toast.error('Failed to generate subject'); + } finally { setIsGeneratingSubject(false); + } };📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.const handleGenerateSubject = async () => { try { setIsGeneratingSubject(true); const { subject } = await generateEmailSubject({ message: editor.getText() }); setValue('subject', subject); } catch (error) { console.error('Error generating subject:', error); toast.error('Failed to generate subject'); } finally { setIsGeneratingSubject(false); } };
Upgraded "drizzle-kit" to 0.31.1 and adjusted "drizzle-orm" versioning for consistency. Additionally, updated Radix dependencies to their latest versions to ensure compatibility and improvements.
Introduced the 'X-Zero-Redirect' header to streamline disconnection handling. Removed client-side redirection logic tied to "Invalid tokens" and updated the fetch interceptor to handle redirects based on the new header. This ensures a cleaner and more centralized redirection flow.
Added `X-Zero-Redirect` to both allowed and exposed headers in CORS configuration to ensure it can be utilized by the client. Removed an unnecessary TRPC error throw related to connection authorization for cleaner response handling.
The X-Zero-Redirect header logic was unnecessary and has been removed to streamline error handling. Error messages and redirection logic are now handled solely through TRPCError.
The error message was unnecessary as the 'UNAUTHORIZED' code is sufficient to convey the issue. This simplifies the error handling and avoids potential redundancy or confusion in the system behavior.
Description
Updated error logic to translate the
invalid_granterror into nulling out theconnection.accessTokenandconnection.refreshToken. Once it is nulled out it will redirect the user to the/settings/connectionspage and display disconnected.When clicking to reconnect the user will be directed through the correct provider connection flow.
Type of Change
Areas Affected
Please check all that apply:
Testing Done
Describe the tests you've done:
Security Considerations
For changes involving data or authentication:
Checklist
Additional Notes
Add any other context about the pull request here.
Screenshots/Recordings
Add screenshots or recordings here if applicable.
By submitting this pull request, I confirm that my contribution is made under the terms of the project's license.
Summary by CodeRabbit
New Features
Bug Fixes
Localization
Error Handling
Database