Skip to content

fix(scan/chat): make the logged-out "Ask Shinny" follow-up actually work - #85

Merged
bejranonda merged 1 commit into
mainfrom
claude/code-review-refactor-212i2
Jul 1, 2026
Merged

fix(scan/chat): make the logged-out "Ask Shinny" follow-up actually work#85
bejranonda merged 1 commit into
mainfrom
claude/code-review-refactor-212i2

Conversation

@bejranonda

@bejranonda bejranonda commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Adversarial self-review of the Round 17 chat hand-off (#84) found the "just ask on chat further" flow was broken for logged-out users β€” three interacting bugs that would each silently drop the follow-up question β€” plus a desktop dead-end and an imprecise seed. All fixed.

The logged-out flow was broken in three ways

  1. Seed eaten on the throwaway mount. takeChatSeed() ran on chat mount before the auth redirect fired, so a logged-out visit cleared the seed during the brief pre-redirect render β€” gone by the time the user returned from login. Now gated on authChecked && isAuthenticated: consumed exactly once, on the mount that actually renders the composer.
  2. No return path through login. Chat's unauth redirect went to /login?mode=login and login always bounced to /dashboard. Chat now passes next=/{locale}/chat; login honours a validated ?next= (same-origin absolute path only β€” rejects //host, /\host, and scheme URLs, so no open redirect).
  3. Desktop Menu/Drink dead-end. The result-action block (Ask Shinny + Scan Another) lived only in the meal branch's desktop sidebar; the shared bottom block was lg:hidden, so on a large screen a Menu/Drink scan had no action buttons at all. Now lg:hidden only for meal (which has the sidebar); visible on all viewports for menu/drink.

Net: a logged-out "Ask Shinny" now round-trips scan β†’ chat β†’ login β†’ back to chat with the question pre-filled.

Also: the generic seed subject is neutral ("this") instead of "my meal", since it fires for menu/drink scans.

Verification

  • type-check + check:i18n (233/233) + 193/193 unit green; next build clean.
  • No e2e pins the old loginβ†’dashboard redirect target, so this is safe against the existing suite. Only pre-existing <img> lint warnings remain (app-wide, not introduced here).

πŸ€– Generated with Claude Code


Generated by Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved the scan-to-chat flow for signed-out users so their progress is preserved after login and the chat opens correctly.
    • Login now returns users to their intended chat page when they sign in.
    • Fixed desktop scan results so action buttons stay visible for all result types and no longer leave a dead-end on larger screens.
  • Style

    • Refined the scan prompt wording in multiple languages to use more neutral, consistent phrasing.

Adversarial self-review of the Round 17 chat hand-off found three
interacting bugs on the logged-out path (all would silently drop the
follow-up question) plus a desktop dead-end and an imprecise seed:

- Seed eaten on the throwaway mount: takeChatSeed() ran on chat mount
  before the auth redirect fired, clearing the seed during the brief
  pre-redirect render. Now gated on authChecked && isAuthenticated, so
  it's consumed exactly once, on the mount that renders the composer.
- No return path: chat's unauth redirect and login both hardcoded
  /dashboard. Chat now passes next=/{locale}/chat; login honours a
  validated same-origin ?next= (rejects //host, /\host, scheme URLs β€”
  no open redirect). The logged-out flow now round-trips scan β†’ chat β†’
  login β†’ back to chat with the question pre-filled.
- Desktop Menu/Drink dead-end: the result-action block was only in the
  meal desktop sidebar; the shared bottom block was lg:hidden, so a
  large-screen menu/drink scan had no buttons at all. Bottom block is
  now lg:hidden only for meal (which has the sidebar), visible on all
  viewports for menu/drink.
- Generic seed subject neutralised ("this" not "my meal") since it
  fires for menu/drink scans.

type-check + i18n (233/233) + 193/193 unit green; next build clean.
No e2e pins the old login→dashboard target.
@bejranonda
bejranonda merged commit 8138f1a into main Jul 1, 2026
3 of 4 checks passed
@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
βš™οΈ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d601e84a-d5de-434c-8d5e-358b8c5afe3e

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 20e737f and 9f295c9.

πŸ“’ Files selected for processing (8)
  • CHANGELOG.md
  • frontend/src/app/[locale]/chat/page.tsx
  • frontend/src/app/[locale]/login/page.tsx
  • frontend/src/app/[locale]/scan/page.tsx
  • frontend/src/messages/da.json
  • frontend/src/messages/de.json
  • frontend/src/messages/en.json
  • frontend/src/messages/th.json

πŸ“ Walkthrough

Walkthrough

This PR hardens the scan β†’ chat context hand-off for logged-out users: the login page now redirects to a safe next path after authentication, the chat page passes an encoded return path and defers seed consumption until auth is confirmed, scan page desktop result actions render consistently, and generic seed prompt text was neutralized across locales.

Changes

Scan to Chat Hand-off Fixes

Layer / File(s) Summary
Safe next-param login redirect
frontend/src/app/[locale]/login/page.tsx
Login redirect now validates a next query parameter against a safe same-origin path pattern and redirects there, falling back to the dashboard if absent or unsafe.
Chat redirect and seed consumption gating
frontend/src/app/[locale]/chat/page.tsx
Unauthenticated redirect passes an encoded next=/{locale}/chat param to login; seeded draft consumption (takeChatSeed) now waits for authChecked and isAuthenticated instead of running on mount regardless of auth state.
Desktop result actions visibility
frontend/src/app/[locale]/scan/page.tsx
Result actions block condition broadened to hasResult && !isAnalyzing, with lg:hidden applied only when a meal result exists, keeping Menu/Drink action buttons visible on desktop.
Generic seed text and changelog
frontend/src/messages/da.json, frontend/src/messages/de.json, frontend/src/messages/en.json, frontend/src/messages/th.json, CHANGELOG.md
ask_seed_generic strings across four locales changed from referencing "my meal" to a neutral "this"; changelog documents the follow-up hardening fixes.

Estimated code review effort: 2 (Simple) | ~15 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant ChatPage
  participant LoginPage
  participant AuthState

  User->>ChatPage: Visit /chat with seeded draft
  ChatPage->>AuthState: Check authChecked/isAuthenticated
  AuthState-->>ChatPage: Not authenticated
  ChatPage->>LoginPage: Redirect to /login?next=/{locale}/chat
  User->>LoginPage: Log in
  LoginPage->>AuthState: isAuthenticated becomes true
  LoginPage->>LoginPage: Validate next param as safe path
  LoginPage->>ChatPage: Redirect to /{locale}/chat
  ChatPage->>AuthState: authChecked & isAuthenticated true
  ChatPage->>ChatPage: takeChatSeed consumes seeded draft
Loading

Possibly related PRs

  • bejranonda/Nutri-Vision-AI#61: Both PRs modify the chat page to gate behavior/redirects on authChecked, addressing logged-out/auth-probe race issues.
✨ Finishing Touches
πŸ“ Generate docstrings
  • Create stacked PR
  • Commit on current branch
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/code-review-refactor-212i2

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.

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