You are working on the hyperswitch repository (Rust payment processing system).…
- User
You are working on the hyperswitch repository (Rust payment processing system).
REPOSITORY SETUP:
- Repository: juspay/hyperswitch
- Working directory: ./repos/hyperswitch_pool_1 (already cloned)
- Base commit: 776bde00efce8be35e0c63c1bdc6215921babddf
- Task ID: juspay__hyperswitch-7844
- Version: v1.113.0
TASK DESCRIPTION: Bug: Last used merchant account context
To enhance the user experience, especially during sign-up or when switching between multiple merchant accounts, we can store the last used merchant account context directly in the users table. This allows the system to automatically restore the previously active context when a user logs in or returns to the dashboard, rather than requiring them to manually select a merchant account each time.
DETAILED CONTEXT & HINTS:
Type of Change
- Bugfix
- New feature
- Enhancement
- Refactoring
- Dependency updates
- Documentation
- CI/CD
Description
This PR introduces lineage context caching to enhance login and account-switch flows with better continuity and reduced DB load.
Key Changes
-
During Login:
- Attempt to fetch the last used
LineageContextfrom Redis (LINEAGE_CONTEXT_<user_id>). - If context is found:
- Validate whether a matching user role exists (using both
V1andV2role versions). - If a valid user_role is found → use this lineage context to issue the JWT token.
- If not → fallback to the default user_role-based resolution logic.
- Validate whether a matching user role exists (using both
- If context is not found in cache, fallback to the existing login flow entirely.
- Attempt to fetch the last used
-
During Account Switch:
- After switching org/merchant/profile context and issuing the new JWT token,
the new
LineageContextis saved to Redis (LINEAGE_CONTEXT_<user_id>). - This allows restoring the last used org/merchant/profile on future logins.
- After switching org/merchant/profile context and issuing the new JWT token,
the new
Assistant
I'll implement the last used merchant account context feature for the hyperswitch repository. Let me start by exploring the codebase to understand the current structure and identify where to make changes.
First, I'll look at the key areas related to user authentication, login flow, and lineage context handling.
Assistant
(no content)
Assistant
Let me look at the router/src/lib.rs file which is likely where the main application logic resides:
Assistant
Let me look at the routes directory to find authentication-related code:
Assistant
Let me search for authentication-related routes, particularly login and user management:
Assistant
Let me look at the user.rs and user_role.rs routes which seem most relevant:
Assistant
Let me also look at the user_role.rs file to understand the user roles and authentication flow:
Assistant
Let me search for the actual core implementation of user sign-in and authentication to understand how it works:
Assistant
(no content)
Assistant
Let me look for the authentication and lineage context handling by looking for specific patterns in the codebase:
Assistant
Let me look at authentication service to understand the current authentication flow:
Assistant
Let me search for more specific authentication patterns:
Assistant
Let me check the Redis interface to understand how Redis is integrated:
Assistant
Now I need to look at the user core module to understand how the signin flow works. Let me examine the key parts more closely:
Assistant
Let me search for the actual sign_in flow function in user core:
Assistant
Now let me examine the specific sign_in function:
Assistant
Let me also look at the NextFlow and token creation to understand the current context:
Assistant
Let me find where the NextFlow and token logic is defined:
Assistant
Let me look for lineage related files or context files:
Assistant
Let me try a broader search to find the context files:
Assistant
Let me examine the user roles to get a better understanding:
Assistant
Based on my investigation of the codebase, I've identified the key areas that need to be modified to implement the last used merchant account context feature. Let me summarize what I found and plan the implementation:
- The authentication/sign-in flow is in
crates/router/src/core/user.rsin thesignin_token_only_flowfunction - Redis integration exists in
crates/redis_interface/src/lib.rs - We need to implement logic to:
- Store LineageContext in Redis during account switches
- Retrieve LineageContext from Redis during login attempts
- Apply the cached context when available, falling back to default behavior when not found or invalid
Let me update my todo list and implement the changes:
- The authentication/sign-in flow is in
Assistant
Looking at the task requirements more carefully, I need to identify where the actual LineageContext logic is implemented, as well as understand how switching between accounts works. Let me search more thoroughly:
Assistant
(no content)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.