Skip to content

Comments

check email for early access#519

Merged
nizzyabi merged 2 commits intostagingfrom
check-early-access-email-session
Mar 26, 2025
Merged

check email for early access#519
nizzyabi merged 2 commits intostagingfrom
check-early-access-email-session

Conversation

@nizzyabi
Copy link
Collaborator

@nizzyabi nizzyabi commented Mar 26, 2025

READ CAREFULLY THEN REMOVE

Remove bullet points that are not relevant.

PLEASE REFRAIN FROM USING AI TO WRITE YOUR CODE AND PR DESCRIPTION. IF YOU DO USE AI TO WRITE YOUR CODE PLEASE PROVIDE A DESCRIPTION AND REVIEW IT CAREFULLY. MAKE SURE YOU UNDERSTAND THE CODE YOU ARE SUBMITTING USING AI.

  • Pull requests that do not follow these guidelines will be closed without review or comment.
  • If you use AI to write your PR description your pr will be close without review or comment.
  • If you are unsure about anything, feel free to ask for clarification.

Description

Please provide a clear description of your changes.


Type of Change

Please delete options that are not relevant.

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature with breaking changes)
  • 📝 Documentation update
  • 🎨 UI/UX improvement
  • 🔒 Security enhancement
  • ⚡ Performance improvement

Areas Affected

Please check all that apply:

  • Email Integration (Gmail, IMAP, etc.)
  • User Interface/Experience
  • Authentication/Authorization
  • Data Storage/Management
  • API Endpoints
  • Documentation
  • Testing Infrastructure
  • Development Workflow
  • Deployment/Infrastructure

Testing Done

Describe the tests you've done:

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed
  • Cross-browser testing (if UI changes)
  • Mobile responsiveness verified (if UI changes)

Security Considerations

For changes involving data or authentication:

  • No sensitive data is exposed
  • Authentication checks are in place
  • Input validation is implemented
  • Rate limiting is considered (if applicable)

Checklist

  • I have read the CONTRIBUTING document
  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in complex areas
  • I have updated the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix/feature works
  • All tests pass locally
  • Any dependent changes are merged and published

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
    • Enhanced user authentication now verifies early access eligibility. Users who do not meet the early access criteria will receive a notification and will not be able to proceed with the sign-in process.

@vercel
Copy link

vercel bot commented Mar 26, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
0 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 26, 2025 5:19am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 26, 2025

Walkthrough

The pull request introduces an early access check in the authentication middleware by modifying the customSession function. It adds an import for earlyAccess from the database schema and updates a query to verify a user's early access status based on their email. If the user lacks early access, an error is thrown, preventing further session processing.

Changes

File(s) Change Summary
apps/mail/lib/auth.ts Adds import for earlyAccess and implements an early access check within customSession, enforcing user validation before session continuation.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant AuthMiddleware
    participant DB
    Client->>AuthMiddleware: Initiate authentication
    AuthMiddleware->>DB: Query earlyAccess table by email
    DB-->>AuthMiddleware: Return early access record
    alt Early access granted
        AuthMiddleware->>Client: Proceed with session
    else Early access denied
        AuthMiddleware->>Client: Throw error, deny session
    end
Loading

Possibly related PRs

Suggested reviewers

  • MrgSub

Poem

In the codey meadow, I happily hop,
Early access now guards each authentication stop.
A whiskered check at the session gate,
Ensures only those with access can participate.
With a joyful twitch and digital cheer,
This rabbit celebrates our changes here! 🐰

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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

@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 (2)
apps/mail/lib/auth.ts (2)

70-80: Early access verification logic implementation looks good.

The implementation properly queries the early access table and verifies if the user has the required permissions before proceeding with authentication. The code follows the existing pattern of using drizzle ORM to query the database.

I have one minor suggestion regarding error handling:

Consider using a more specific error type or adding an error code to make it easier to handle this specific error case in the UI layer:

- throw new Error("Early access required. Please join the waitlist.");
+ throw new Error("EARLY_ACCESS_REQUIRED: Please join the waitlist.");

Or even better, create a custom error class:

class EarlyAccessRequiredError extends Error {
  constructor(message = "Early access required. Please join the waitlist.") {
    super(message);
    this.name = "EarlyAccessRequiredError";
  }
}

// Then use it like:
throw new EarlyAccessRequiredError();

70-80: Consider case sensitivity in email comparison.

The current implementation directly compares emails without handling potential case sensitivity issues. While most email providers treat emails as case-insensitive, the database comparison might be case-sensitive depending on the collation settings.

Consider normalizing the email address before comparison:

      // First, check if user has early access
      const [earlyAccessUser] = await db
        .select()
        .from(earlyAccess)
-       .where(eq(earlyAccess.email, user.email))
+       .where(eq(earlyAccess.email, user.email.toLowerCase()))
        .limit(1);

Additionally, ensure that emails are consistently stored in lowercase in the early_access table.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between de4231d and bf61b00.

📒 Files selected for processing (1)
  • apps/mail/lib/auth.ts (2 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
apps/mail/lib/auth.ts (2)
packages/db/src/index.ts (1)
  • db (17-17)
packages/db/src/schema.ts (2)
  • earlyAccess (57-63)
  • user (6-15)
🔇 Additional comments (3)
apps/mail/lib/auth.ts (3)

2-2: Updated import statement to include early access functionality.

The import statement now includes earlyAccess from the database schema, which is necessary for the early access check implementation.


70-76: Verify error handling for database query failures.

The query to check for early access could fail due to database connectivity issues or other reasons. The current implementation doesn't handle these potential errors explicitly.

Consider adding try-catch blocks around the database query to gracefully handle potential database errors:

+     try {
        // First, check if user has early access
        const [earlyAccessUser] = await db
          .select()
          .from(earlyAccess)
          .where(eq(earlyAccess.email, user.email))
          .limit(1);
+     } catch (error) {
+       console.error("Failed to check early access status:", error);
+       throw new Error("Unable to verify access status. Please try again later.");
+     }

77-80: Verify that the error message is properly displayed to users.

The error message "Early access required. Please join the waitlist." is informative, but we should ensure it's properly displayed to users rather than being shown as a generic error.

Please verify that the error thrown here is properly caught and displayed in the UI, with appropriate guidance for users to join the waitlist. You might want to verify how error handling is implemented in the authentication flow.

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/lib/auth.ts (1)

82-84: Suggest adding test coverage for the early access logic.

Throwing an error prevents further session handling when hasEarlyAccess is falsy. This appears correct but should be tested to ensure reliable behavior.

Would you like me to generate a test for verifying that non-early-access users cannot proceed?

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between bf61b00 and e8c7a9b.

📒 Files selected for processing (1)
  • apps/mail/lib/auth.ts (2 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
apps/mail/lib/auth.ts (2)
packages/db/src/index.ts (1)
  • db (17-17)
packages/db/src/schema.ts (2)
  • earlyAccess (57-63)
  • user (6-15)
🔇 Additional comments (4)
apps/mail/lib/auth.ts (4)

2-2: No issues with the new import.

Importing earlyAccess seems correct and aligns with the updated logic.


70-70: Thanks for the descriptive comment.

This clarifies the intention behind combining the user lookup with the early access check. No changes needed.


74-77: Ensure intended behavior for missing early access rows.

Using a left join to fetch hasEarlyAccess implies that users without an early_access record will be treated as lacking early access. Confirm if this strict approach aligns with product requirements. Otherwise, consider an inner join or separate logic to handle missing entries distinctly.


81-81: No additional feedback on the comment.

@nizzyabi nizzyabi merged commit aa44450 into staging Mar 26, 2025
5 checks passed
nizzyabi added a commit that referenced this pull request Mar 26, 2025
* adjustable height

* h1 h2 h3 working in reply composer

* select dropdown for categories

* feat(navbar): update item label based on auth status

* feature/persist user settings (#513)

* feat: persist setting (codycodes95)

* feat: update settings to jsonb

* feat: run migration

* feat: save changes to db

* fix: naming

* feat: validate settings schema

* feat: add i18n

* fix: set i18n variables

* fix: coderabbit comment

* feat: improve function readability

* feat: use hook

* fix:update settings

---------

Co-authored-by: Cody Partington <codythatsme@gmail.com>

* remove unique status from email in schema

* early access check added to schema

* updated readme

* add contributors

* remove text-decoration

* text-decoration

* remove auto focus on search

* ahuh

* gg

* i18n

* check email for early access (#519)

* check email for early access

* one check

* saving...

* disable buttons

* disable

* fix

* saving...

---------

Co-authored-by: Nizzy <nizabizaher@gmail.com>
Co-authored-by: pietrodev07 <pietro.dev.07@gmail.com>
Co-authored-by: Sergio JVA <60497216+sergio-jva@users.noreply.github.com>
Co-authored-by: Cody Partington <codythatsme@gmail.com>
Co-authored-by: Ahmet Kilinc <akx9@icloud.com>
Co-authored-by: user12224 <122770437+user12224@users.noreply.github.com>
Co-authored-by: nizzy <140507264+nizzyabi@users.noreply.github.com>
nizzyabi added a commit that referenced this pull request Apr 1, 2025
* adjustable height

* h1 h2 h3 working in reply composer

* select dropdown for categories

* feat(navbar): update item label based on auth status

* feature/persist user settings (#513)

* feat: persist setting (codycodes95)

* feat: update settings to jsonb

* feat: run migration

* feat: save changes to db

* fix: naming

* feat: validate settings schema

* feat: add i18n

* fix: set i18n variables

* fix: coderabbit comment

* feat: improve function readability

* feat: use hook

* fix:update settings

---------

Co-authored-by: Cody Partington <codythatsme@gmail.com>

* remove unique status from email in schema

* early access check added to schema

* updated readme

* add contributors

* remove text-decoration

* text-decoration

* remove auto focus on search

* ahuh

* gg

* i18n

* check email for early access (#519)

* check email for early access

* one check

* saving...

* disable buttons

* disable

* fix

* saving...

* saving...

* minor

* New translations en.json (French)

* New translations en.json (Spanish)

* New translations en.json (Arabic)

* New translations en.json (Catalan)

* New translations en.json (Czech)

* New translations en.json (German)

* New translations en.json (Japanese)

* New translations en.json (Korean)

* New translations en.json (Polish)

* New translations en.json (Portuguese)

* New translations en.json (Russian)

* New translations en.json (Turkish)

* New translations en.json (Latvian)

* New translations en.json (Hindi)

* New translations en.json (French)

* New translations en.json (Spanish)

* New translations en.json (Arabic)

* New translations en.json (Catalan)

* New translations en.json (German)

* New translations en.json (Japanese)

* New translations en.json (Korean)

* New translations en.json (Polish)

* New translations en.json (Portuguese)

* New translations en.json (Hindi)

* reply and searchbar display

* reply ai (#526)

* reply ai

* ai functionality

* line height

* adam fixes

---------

Co-authored-by: user12224 <122770437+user12224@users.noreply.github.com>
Co-authored-by: Nizzy <nizabizaher@gmail.com>

* Autocompletions for reply and create

* email avatars (#528)

* added email avatars

* fix small issue

* small ui fix

* color fix

* reply ui

* New translations en.json (Japanese)

* New translations en.json (Korean)

* no drop down

* ui fix

* wip performance

* saving...

* saving...

* saving...

* saving...

* - updated phrases
- added delay of 2 matching characters

* Improved ai with custom prompt (#534)

* ai

* improved ai

* improved-ai-with-custom-prompt

* empty commit

* removed new lines

* empty commit

* search

* forwarding

* search filter removed. all in ai now

* saving...

* fix double submit on command enter create email

* saving...

* saving...

* turn search ai into a server action

* fuix

* show most recent email in thread

* saving...

* saving...

* forward and reply in one compose button

* saving...

* New translations en.json (French)

* New translations en.json (Spanish)

* New translations en.json (Arabic)

* New translations en.json (Catalan)

* New translations en.json (Czech)

* New translations en.json (German)

* New translations en.json (Japanese)

* New translations en.json (Korean)

* New translations en.json (Polish)

* New translations en.json (Portuguese)

* New translations en.json (Russian)

* New translations en.json (Turkish)

* New translations en.json (Latvian)

* New translations en.json (Hindi)

* fix to height reply composer

* posthog

* remove github login for now

* refresh

* New translations en.json (French)

* New translations en.json (Spanish)

* New translations en.json (Arabic)

* New translations en.json (Catalan)

* New translations en.json (Czech)

* New translations en.json (German)

* New translations en.json (Japanese)

* New translations en.json (Korean)

* New translations en.json (Polish)

* New translations en.json (Portuguese)

* New translations en.json (Russian)

* New translations en.json (Turkish)

* New translations en.json (Latvian)

* New translations en.json (Hindi)

* revert

* a

* fix load more

* fix load more

* remove use memo from thread to not load when opening an email

* fix switching accounts

---------

Co-authored-by: Nizzy <nizabizaher@gmail.com>
Co-authored-by: pietrodev07 <pietro.dev.07@gmail.com>
Co-authored-by: Sergio JVA <60497216+sergio-jva@users.noreply.github.com>
Co-authored-by: Cody Partington <codythatsme@gmail.com>
Co-authored-by: Ahmet Kilinc <akx9@icloud.com>
Co-authored-by: user12224 <122770437+user12224@users.noreply.github.com>
Co-authored-by: nizzy <140507264+nizzyabi@users.noreply.github.com>
Co-authored-by: [bot] <zero@ibra.rip>
Co-authored-by: needle <122770437+needleXO@users.noreply.github.com>
nizzyabi added a commit that referenced this pull request Apr 1, 2025
* adjustable height

* h1 h2 h3 working in reply composer

* select dropdown for categories

* feat(navbar): update item label based on auth status

* feature/persist user settings (#513)

* feat: persist setting (codycodes95)

* feat: update settings to jsonb

* feat: run migration

* feat: save changes to db

* fix: naming

* feat: validate settings schema

* feat: add i18n

* fix: set i18n variables

* fix: coderabbit comment

* feat: improve function readability

* feat: use hook

* fix:update settings

---------

Co-authored-by: Cody Partington <codythatsme@gmail.com>

* remove unique status from email in schema

* early access check added to schema

* updated readme

* add contributors

* remove text-decoration

* text-decoration

* remove auto focus on search

* ahuh

* gg

* i18n

* check email for early access (#519)

* check email for early access

* one check

* saving...

* disable buttons

* disable

* fix

* saving...

* saving...

* minor

* New translations en.json (French)

* New translations en.json (Spanish)

* New translations en.json (Arabic)

* New translations en.json (Catalan)

* New translations en.json (Czech)

* New translations en.json (German)

* New translations en.json (Japanese)

* New translations en.json (Korean)

* New translations en.json (Polish)

* New translations en.json (Portuguese)

* New translations en.json (Russian)

* New translations en.json (Turkish)

* New translations en.json (Latvian)

* New translations en.json (Hindi)

* New translations en.json (French)

* New translations en.json (Spanish)

* New translations en.json (Arabic)

* New translations en.json (Catalan)

* New translations en.json (German)

* New translations en.json (Japanese)

* New translations en.json (Korean)

* New translations en.json (Polish)

* New translations en.json (Portuguese)

* New translations en.json (Hindi)

* reply and searchbar display

* reply ai (#526)

* reply ai

* ai functionality

* line height

* adam fixes

---------

Co-authored-by: user12224 <122770437+user12224@users.noreply.github.com>
Co-authored-by: Nizzy <nizabizaher@gmail.com>

* Autocompletions for reply and create

* email avatars (#528)

* added email avatars

* fix small issue

* small ui fix

* color fix

* reply ui

* New translations en.json (Japanese)

* New translations en.json (Korean)

* no drop down

* ui fix

* wip performance

* saving...

* saving...

* saving...

* saving...

* - updated phrases
- added delay of 2 matching characters

* Improved ai with custom prompt (#534)

* ai

* improved ai

* improved-ai-with-custom-prompt

* empty commit

* removed new lines

* empty commit

* search

* forwarding

* search filter removed. all in ai now

* saving...

* fix double submit on command enter create email

* saving...

* saving...

* turn search ai into a server action

* fuix

* show most recent email in thread

* saving...

* saving...

* forward and reply in one compose button

* saving...

* New translations en.json (French)

* New translations en.json (Spanish)

* New translations en.json (Arabic)

* New translations en.json (Catalan)

* New translations en.json (Czech)

* New translations en.json (German)

* New translations en.json (Japanese)

* New translations en.json (Korean)

* New translations en.json (Polish)

* New translations en.json (Portuguese)

* New translations en.json (Russian)

* New translations en.json (Turkish)

* New translations en.json (Latvian)

* New translations en.json (Hindi)

* fix to height reply composer

* posthog

* remove github login for now

* refresh

* New translations en.json (French)

* New translations en.json (Spanish)

* New translations en.json (Arabic)

* New translations en.json (Catalan)

* New translations en.json (Czech)

* New translations en.json (German)

* New translations en.json (Japanese)

* New translations en.json (Korean)

* New translations en.json (Polish)

* New translations en.json (Portuguese)

* New translations en.json (Russian)

* New translations en.json (Turkish)

* New translations en.json (Latvian)

* New translations en.json (Hindi)

* revert

* a

* fix load more

* fix load more

* remove use memo from thread to not load when opening an email

* fix switching accounts

* navbar changed to login

---------

Co-authored-by: Nizzy <nizabizaher@gmail.com>
Co-authored-by: pietrodev07 <pietro.dev.07@gmail.com>
Co-authored-by: Sergio JVA <60497216+sergio-jva@users.noreply.github.com>
Co-authored-by: Cody Partington <codythatsme@gmail.com>
Co-authored-by: Adam <x_1337@outlook.com>
Co-authored-by: Ahmet Kilinc <akx9@icloud.com>
Co-authored-by: user12224 <122770437+user12224@users.noreply.github.com>
Co-authored-by: nizzy <140507264+nizzyabi@users.noreply.github.com>
Co-authored-by: [bot] <zero@ibra.rip>
@coderabbitai coderabbitai bot mentioned this pull request Apr 3, 2025
34 tasks
@coderabbitai coderabbitai bot mentioned this pull request Apr 16, 2025
@BlankParticle BlankParticle deleted the check-early-access-email-session branch May 25, 2025 13:42
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