Skip to content

fix cookie issue#1002

Merged
BilalG1 merged 1 commit intodevfrom
fix-cookie-issue
Nov 6, 2025
Merged

fix cookie issue#1002
BilalG1 merged 1 commit intodevfrom
fix-cookie-issue

Conversation

@BilalG1
Copy link
Contributor

@BilalG1 BilalG1 commented Nov 6, 2025

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Enhanced platform-specific handling for cookie refresh operations with improved error detection and logging.

@vercel
Copy link

vercel bot commented Nov 6, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
stack-backend Ready Ready Preview Comment Nov 6, 2025 6:33pm
stack-dashboard Ready Ready Preview Comment Nov 6, 2025 6:33pm
stack-demo Ready Ready Preview Comment Nov 6, 2025 6:33pm
stack-docs Ready Ready Preview Comment Nov 6, 2025 6:33pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 6, 2025

Walkthrough

Modified hostname retrieval logic in the client app implementation to conditionally handle browser versus non-browser platforms. Replaced unconditional hostname assignment with an else-guarded approach and added console warning for missing hostname scenarios.

Changes

Cohort / File(s) Change Summary
Client App Platform Handling
packages/template/src/lib/stack-app/apps/implementations/client-app-impl.ts
Modified _queueCustomRefreshCookieUpdate method: hostname retrieval now uses conditional logic (else branch) to differentiate browser vs non-browser platforms; added console.warn for missing hostname; existing logic preserved

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Review the conditional logic change for browser vs non-browser platform handling
  • Verify console.warn placement and message appropriateness for missing hostname scenarios
  • Confirm no regressions in existing hostname assignment behavior for supported platforms

Poem

🐰 A hop through the code, a branch so divine,
Platform detection now draws the fine line,
Browser or not, we now know the way,
With warnings that whisper when hosts go astray! 🌿

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is empty except for an HTML comment with a link to CONTRIBUTING.md guidelines; it lacks any meaningful explanation of the changes, the issue being fixed, or the rationale. Add a detailed description explaining the cookie issue, why it occurred, what changes were made, and how they resolve the problem.
Title check ❓ Inconclusive The title 'fix cookie issue' is vague and generic, using non-descriptive language that doesn't clearly convey what specific cookie-related problem is being fixed or which code area is affected. Replace with a more specific title that describes the actual fix, such as 'Guard hostname retrieval in _queueCustomRefreshCookieUpdate for non-browser platforms' or similar.
✅ Passed checks (1 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-cookie-issue

📜 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 e31bba4 and d0fa450.

📒 Files selected for processing (1)
  • packages/template/src/lib/stack-app/apps/implementations/client-app-impl.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
  • GitHub Check: Vercel Agent Review
  • GitHub Check: check_prisma_migrations (22.x)
  • GitHub Check: build (22.x)
  • GitHub Check: build (22.x)
  • GitHub Check: docker
  • GitHub Check: build (22.x)
  • GitHub Check: restart-dev-and-test-with-custom-base-port
  • GitHub Check: restart-dev-and-test
  • GitHub Check: all-good
  • GitHub Check: setup-tests
  • GitHub Check: lint_and_build (latest)
🔇 Additional comments (1)
packages/template/src/lib/stack-app/apps/implementations/client-app-impl.ts (1)

593-599: LGTM - Good fix for the hostname retrieval logic!

The else branch correctly separates browser vs. non-browser hostname retrieval, preventing the browser hostname from being overwritten. The console warning and early return appropriately handle the edge case where no hostname is available.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Overview

Greptile Summary

Fixed a control flow bug in _queueCustomRefreshCookieUpdate where the server-side hostname lookup was unconditionally overwriting the browser hostname. The bug was introduced in PR #971 when the Next.js platform-specific code wasn't wrapped in an else block, causing the server's sc.headers() call to always execute and override window.location.hostname even in browser contexts.

Key changes:

  • Added else block around Next.js server hostname retrieval (line 593-595)
  • Added warning log when hostname cannot be determined (line 598)

This ensures proper hostname detection for cookie domain configuration in both browser and Next.js server environments.

Confidence Score: 5/5

  • This PR is safe to merge - it fixes a critical control flow bug with a minimal, surgical change
  • The fix addresses a clear logic error where server code was executing in browser context, overwriting the correct hostname value. The change is minimal (adding one else block), follows the platform conditional pattern used elsewhere in the codebase, and adds helpful debugging with the console.warn. No security issues or unintended side effects introduced.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
packages/template/src/lib/stack-app/apps/implementations/client-app-impl.ts 5/5 Fixed control flow bug where server hostname was always overwriting browser hostname by adding else block

Sequence Diagram

sequenceDiagram
    participant App as Client App
    participant Func as _queueCustomRefreshCookieUpdate
    participant Browser as Browser Check
    participant Server as Next.js Server (sc.headers)
    participant Cache as _trustedParentDomainCache
    participant Cookie as setCookie

    App->>Func: Call with refreshToken, updatedAt, context
    Func->>Browser: isBrowserLike()?
    
    alt Browser Environment
        Browser-->>Func: true
        Func->>Func: hostname = window.location.hostname
    else Server Environment (Next.js)
        Browser-->>Func: false
        Func->>Server: await sc.headers().get("host")
        Server-->>Func: hostname from headers
    end
    
    alt No hostname found
        Func->>Func: console.warn() and return
    else Hostname found
        Func->>Cache: getOrWait([hostname])
        Cache-->>Func: trusted parent domain
        Func->>Cookie: Set/delete cookie with domain
    end
Loading

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

@BilalG1 BilalG1 merged commit 5c816a0 into dev Nov 6, 2025
24 checks passed
@BilalG1 BilalG1 deleted the fix-cookie-issue branch November 6, 2025 19:02
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