Skip to content

Clean up dead auth route guards and mail bootstrap#26

Merged
ruoliu2 merged 5 commits into
mainfrom
codex/cleanup-auth-route-dead-code
Mar 9, 2026
Merged

Clean up dead auth route guards and mail bootstrap#26
ruoliu2 merged 5 commits into
mainfrom
codex/cleanup-auth-route-dead-code

Conversation

@ruoliu2
Copy link
Copy Markdown
Owner

@ruoliu2 ruoliu2 commented Mar 9, 2026

Summary

  • remove dead server-side auth route guards that relied on Next server cookies
  • simplify the /mail route to stop carrying unused server session and thread prefetch code
  • flatten the mail workspace back to a single client-side auth bootstrap path

Why

In the current deployment, the auth session cookie lives on the Railway API origin, not the Vercel web origin. That made the server-side guards and bootstrap branches in the route layer misleading at best and wrong at worst. This PR removes those stale paths instead of preserving half-used fallback logic.

Validation

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

Open with Devin

ruoliu2 added 3 commits March 9, 2026 14:28
Signed-off-by: ruo <ruoliu.dev@gmail.com>
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:52
@gemini-code-assist
Copy link
Copy Markdown
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 refactors the application's authentication and mail loading mechanisms to align with the current deployment environment. It removes outdated and non-functional server-side authentication checks and data prefetching, which were ineffective due to cross-origin cookie handling. The changes simplify the codebase by moving to a purely client-side authentication bootstrap for the mail workspace, enhancing robustness and maintainability.

Highlights

  • Removed Dead Server-Side Authentication Guards: Eliminated server-side route guards that relied on Next.js server cookies, which were no longer functional due to the auth session cookie residing on a different origin (Railway API vs. Vercel web).
  • Simplified Mail Route Bootstrap: Streamlined the /mail route by removing unused server session and thread prefetch code, consolidating the mail workspace to a single client-side authentication bootstrap path.
  • Consolidated Authentication Logic: Flattened the authentication flow, removing misleading or incorrect server-side fallback logic and ensuring all authentication bootstrapping occurs client-side.
Changelog
  • apps/web/app/page.tsx
    • Removed imports for cookies and SESSION_COOKIE_NAME.
    • Eliminated conditional redirect logic based on session cookie presence.
    • Modified the page to always redirect to the /auth route.
  • packages/app/src/routes/auth-guard.ts
    • Removed the entire auth-guard.ts file, which contained server-side authentication status and redirection utilities.
  • packages/app/src/routes/auth-page.tsx
    • Removed the import and usage of redirectIfAuthenticated.
    • Converted AuthPage from an async function to a synchronous function.
  • packages/app/src/routes/mail-page.tsx
    • Removed imports related to server-side cookie handling, API base, and authentication types.
    • Deleted serverRequest and serverRequestOrNull utility functions.
    • Converted MailPage from an async function to a synchronous function.
    • Removed the call to redirectIfUnauthenticated.
    • Eliminated server-side fetching of initial session and thread page data.
    • Updated MailWorkspace component to no longer receive initialSession or initialThreadPage props.
  • packages/features/src/mail/mail-workspace.tsx
    • Removed the ThreadSummaryPage type import.
    • Removed initialSession and initialThreadPage from MailWorkspaceProps.
    • Updated state initializations for session, sessionChecked, threads, loadingList, nextPageToken, and hasMore to remove reliance on initial props.
    • Removed the bootstrappedListRef and associated logic.
    • Deleted a useEffect hook responsible for processing initial thread page data.
    • Modified a useEffect hook to remove conditional returns and initialSession from its dependency array, simplifying session loading.
Activity
  • No specific activity (comments, reviews, progress) has been recorded for this pull request yet.
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
Copy Markdown
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 4 additional findings.

Open in Devin Review

Signed-off-by: ruo <ruoliu.dev@gmail.com>
Copy link
Copy Markdown

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 stale Next.js server-side auth guards and server-prefetch/bootstrap logic for the mail route, aligning the web UI with the current deployment where the session cookie is set on the API origin (not the Vercel web origin).

Changes:

  • Remove server-side auth guard utilities and cookie-based redirects.
  • Convert /mail and /auth routes to a single client-driven session bootstrap flow.
  • Simplify MailWorkspace by dropping unused initialSession / initialThreadPage props and associated bootstrap logic.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/features/src/mail/mail-workspace.tsx Removes SSR bootstrap inputs and relies on client-side session + initial thread loading.
packages/app/src/routes/mail-page.tsx Drops server fetch/prefetch + redirect guard; passes only initialThreadId into the client workspace.
packages/app/src/routes/auth-page.tsx Removes server-side redirect guard; renders auth UI directly.
packages/app/src/routes/auth-guard.ts Deletes dead cookie-based server auth guard implementation.
apps/web/app/page.tsx Removes cookie-based redirect; always redirects root to /auth.

💡 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.

Comment on lines 576 to 580
if (isMounted) {
setSessionChecked(true);
}
}
}
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

The mailbox/search change effect clears selectedThreadId unconditionally. On initial mount this will wipe out initialThreadId from the ?thread= URL param, so deep-linking to a specific thread won’t work (the thread fetch started by the initial state gets cancelled once the id is reset to null). Consider preserving the initial selection on first load (e.g., only clear selection when the user changes mailbox/search, or track a “hasInitialized” ref before calling setSelectedThreadId(null)).

Copilot uses AI. Check for mistakes.
Comment on lines +284 to 287
const [threads, setThreads] = useState<ThreadListItem[]>([]);
const [selectedThreadId, setSelectedThreadId] = useState<string | null>(
initialThreadId ?? null,
);
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

selectedThreadId is initialized from initialThreadId before the session check runs. Now that server-side guards are removed, this can trigger a thread fetch for unauthenticated users (or before session is confirmed), leading to a spurious 401/error flash and an unnecessary request. Consider deferring application of initialThreadId until sessionChecked && session?.authenticated, or gating the thread-loading effect on authenticated session state.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
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

The code changes remove the authentication logic from the client-side routes and components, specifically removing the use of cookies and server requests to determine session status. The authentication checks and redirects are removed from the landing page (/), the auth-guard file, and the MailPage component. The AuthPage component no longer redirects authenticated users. The MailWorkspace component no longer receives initial session or thread page data as props and initializes its state accordingly.

Signed-off-by: ruo <ruoliu.dev@gmail.com>
@ruoliu2 ruoliu2 merged commit a959547 into main Mar 9, 2026
8 of 9 checks passed
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