Skip to content

Fix mail route for cross-origin auth cookie#25

Open
ruoliu2 wants to merge 2 commits intomainfrom
codex/fix-cross-origin-mail-route
Open

Fix mail route for cross-origin auth cookie#25
ruoliu2 wants to merge 2 commits intomainfrom
codex/fix-cross-origin-mail-route

Conversation

@ruoliu2
Copy link
Owner

@ruoliu2 ruoliu2 commented Mar 9, 2026

Summary

  • remove the server-side auth redirect from /mail entirely
  • let the mail page render and bootstrap auth from the client API session, the same way /calendar already does
  • keep server prefetch as best effort only

Root cause

Production auth uses a session cookie on the Railway API origin. The Vercel Next server does not receive that cookie, so any /mail redirect based on Next server cookies or a server-side auth probe will incorrectly send authenticated users back to /auth. That is why auth/session and calendar worked, but /mail flashed and bounced.

Validation

  • bun run build in apps/web
  • uvx pre-commit run --files packages/app/src/routes/auth-guard.ts packages/app/src/routes/mail-page.tsx

Open with Devin

ruoliu2 added 2 commits March 9, 2026 14:28
Signed-off-by: ruo <ruoliu.dev@gmail.com>
Signed-off-by: ruo <ruoliu.dev@gmail.com>
Copilot AI review requested due to automatic review settings March 9, 2026 21:46
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an authentication issue where the /mail route incorrectly redirected authenticated users to /auth due to the Next.js server not receiving the session cookie from the Railway API origin. The solution involves shifting the authentication responsibility for the /mail page to the client-side, allowing it to bootstrap authentication from the client API session, similar to the /calendar route. This change ensures that authenticated users can access the mail page without unexpected redirects.

Highlights

  • Authentication Redirect Removal: The server-side authentication redirect from the /mail route has been entirely removed.
  • Client-Side Authentication: The mail page now renders and bootstraps authentication from the client API session, aligning with how the /calendar route already handles it.
  • Server Prefetch Adjustment: Server prefetch is now treated as a best-effort mechanism only.
Changelog
  • packages/app/src/routes/mail-page.tsx
    • Removed the import of redirectIfUnauthenticated.
    • Removed the call to redirectIfUnauthenticated() within the MailPage component.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request addresses an authentication issue on the /mail route caused by cross-origin cookies. The fix involves removing the server-side authentication check and redirect, and instead relying on the client-side to manage the authentication session. This aligns the /mail route's behavior with what is described as the existing behavior for the /calendar route. The server-side data prefetching is now treated as a best-effort operation. The changes are correct and effectively resolve the issue by adopting a common pattern for handling authentication in applications with a separate frontend and backend.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Removes the server-side auth redirect from the /mail route so authenticated users aren’t incorrectly bounced to /auth when the session cookie lives on the API origin (cross-origin). This aligns /mail with the existing client-bootstrapped auth flow already used by the mail UI (and described as matching /calendar behavior).

Changes:

  • Removed the server-side redirectIfUnauthenticated() call from MailPage.
  • Removed the now-unneeded redirectIfUnauthenticated import.
  • Kept server-side prefetch of session/thread data as best-effort (nullable) bootstrapping.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

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