UN-2971 [FEAT] Pass selectedProduct to login/signup API for OAuth product scope#1803
UN-2971 [FEAT] Pass selectedProduct to login/signup API for OAuth product scope#1803johnyrahul merged 2 commits intomainfrom
Conversation
…duct scope 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Summary by CodeRabbit
WalkthroughThe login component now supports product-aware authentication by reading a selectedProduct value from localStorage. When a valid product is detected from a predefined list, it automatically appends this as a query parameter to both login and signup URLs, enabling product context to persist through the authentication flow. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. 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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
frontend/src/components/log-in/Login.jsx (2)
22-34: Consolidate duplicate URL construction and addencodeURIComponentdefensively.
handleLoginandhandleSignupare identical modulo the path string. A small helper eliminates the duplication. Additionally,selectedProductis interpolated directly into the URL; encoding it is a safe, future-proof habit even though the current whitelist values don't require it.♻️ Proposed refactor
- const handleLogin = () => { - const loginUrl = isValidProduct - ? `${baseUrl}/api/v1/login?selectedProduct=${selectedProduct}` - : `${baseUrl}/api/v1/login`; - window.location.href = loginUrl; - }; - - const handleSignup = () => { - const signupUrl = isValidProduct - ? `${baseUrl}/api/v1/signup?selectedProduct=${selectedProduct}` - : `${baseUrl}/api/v1/signup`; - window.location.href = signupUrl; - }; + const buildAuthUrl = (path) => { + const base = `${baseUrl}/api/v1/${path}`; + return isValidProduct + ? `${base}?selectedProduct=${encodeURIComponent(selectedProduct)}` + : base; + }; + + const handleLogin = () => { window.location.href = buildAuthUrl("login"); }; + const handleSignup = () => { window.location.href = buildAuthUrl("signup"); };🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@frontend/src/components/log-in/Login.jsx` around lines 22 - 34, DRY the URL construction in handleLogin and handleSignup by extracting a small helper (e.g., buildAuthUrl or constructAuthUrl) that accepts the path ('/api/v1/login' or '/api/v1/signup') and returns `${baseUrl}${path}` plus `?selectedProduct=${encodeURIComponent(selectedProduct)}` only when isValidProduct is true; update handleLogin and handleSignup to call that helper and set window.location.href to its result, ensuring selectedProduct is passed through encodeURIComponent for safety.
19-20: Extract the valid-product list to a shared constant.
["unstract", "llm-whisperer"]is hardcoded inline. SinceselectedProductis also consumed inPersistentLogin.jsanduseSessionValid.js, any future product addition risks drift if defined separately in each file. Exporting fromGetStaticData.jsprovides a single source of truth.♻️ Proposed refactor
In
frontend/src/helpers/GetStaticData.js, add the constant:+export const VALID_PRODUCTS = ["unstract", "llm-whisperer"];Then in
Login.jsx, import and use it:-import { getBaseUrl } from "../../helpers/GetStaticData"; +import { getBaseUrl, VALID_PRODUCTS } from "../../helpers/GetStaticData"; ... -const isValidProduct = - selectedProduct && ["unstract", "llm-whisperer"].includes(selectedProduct); +const isValidProduct = selectedProduct && VALID_PRODUCTS.includes(selectedProduct);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@frontend/src/components/log-in/Login.jsx` around lines 19 - 20, Extract the hardcoded product list into a shared exported constant (e.g., VALID_PRODUCTS) in GetStaticData.js and replace the inline array used to compute isValidProduct in Login.jsx with an import of that constant; update other consumers (PersistentLogin.js and useSessionValid.js) to import and use the same VALID_PRODUCTS constant so all files reference a single source of truth for valid products (ensure the symbol name matches across imports and update any tests or imports accordingly).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@frontend/src/components/log-in/Login.jsx`:
- Around line 22-34: DRY the URL construction in handleLogin and handleSignup by
extracting a small helper (e.g., buildAuthUrl or constructAuthUrl) that accepts
the path ('/api/v1/login' or '/api/v1/signup') and returns `${baseUrl}${path}`
plus `?selectedProduct=${encodeURIComponent(selectedProduct)}` only when
isValidProduct is true; update handleLogin and handleSignup to call that helper
and set window.location.href to its result, ensuring selectedProduct is passed
through encodeURIComponent for safety.
- Around line 19-20: Extract the hardcoded product list into a shared exported
constant (e.g., VALID_PRODUCTS) in GetStaticData.js and replace the inline array
used to compute isValidProduct in Login.jsx with an import of that constant;
update other consumers (PersistentLogin.js and useSessionValid.js) to import and
use the same VALID_PRODUCTS constant so all files reference a single source of
truth for valid products (ensure the symbol name matches across imports and
update any tests or imports accordingly).
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to Reviews > Disable Cache setting
Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting
📒 Files selected for processing (1)
frontend/src/components/log-in/Login.jsx
Signed-off-by: Hari John Kuriakose <hari@zipstack.com>
|
…duct scope (#1803) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: Hari John Kuriakose <hari@zipstack.com> Co-authored-by: Claude <noreply@anthropic.com>



What
selectedProductquery parameter from frontend to login/signup API endpointsWhy
product:unstractorproduct:llm-whisperer) in the authorization flowHow
selectedProductfrom localStorage in the Login componenthandleSignupfunction that constructs signup URL withselectedProductquery parameterhandleLoginfunction to also includeselectedProductquery parameterhandleSignupto the LoginForm plugin componentCan this PR break any existing features. If yes, please list possible items. If no, please explain why. (PS: Admins do not merge the PR without this section filled)
selectedProductis not present or invalid, the API calls work without the query parameter (same as before).Database Migrations
Env Config
Relevant Docs
Related Issues or PRs
Dependencies Versions
Notes on Testing
?selectedProduct=<product>query parameterScreenshots
N/A
Checklist
I have read and understood the Contribution Guidelines.
🤖 Generated with Claude Code