-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor useEffect logic to simplify impersonation mode check #2199
base: develop
Are you sure you want to change the base?
Conversation
sunilsabatp
commented
Aug 26, 2024
•
edited
Loading
edited
- Changed useEffect to directly set impersonation mode based on localStorage check.
- Removed redundant conditional check.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughThe recent changes involve modifications to the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant UserPropsProvider
participant API
User->>UserPropsProvider: Check impersonation status
UserPropsProvider->>localStorage: Get impersonationData
localStorage-->>UserPropsProvider: Return impersonationData
UserPropsProvider-->>User: Set isImpersonationModeOn
User->>API: Make authenticated request
API->>localStorage: Check token validity
alt Invalid token
API->>localStorage: Remove impersonationData
end
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Outside diff range, codebase verification and nitpick comments (1)
src/utils/apiRequests/api.ts (1)
Line range hint
1-28
: Reminder: Add error handling.The TODO comment indicates that error handling is missing in the
getAccountInfo
function.Do you want me to generate the error handling code or open a GitHub issue to track this task?
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- src/features/common/Layout/UserPropsContext.tsx (1 hunks)
- src/utils/apiRequests/api.ts (4 hunks)
Files skipped from review due to trivial changes (1)
- src/features/common/Layout/UserPropsContext.tsx
Additional comments not posted (4)
src/utils/apiRequests/api.ts (4)
121-123
: LGTM!The code correctly removes
impersonationData
from local storage and logs out the user when an invalid token is detected.The code changes are approved.
172-174
: LGTM!The code correctly removes
impersonationData
from local storage and logs out the user when an invalid token is detected.The code changes are approved.
255-257
: LGTM!The code correctly removes
impersonationData
from local storage and logs out the user when an invalid token is detected.The code changes are approved.
304-306
: LGTM!The code correctly removes
impersonationData
from local storage and logs out the user when an invalid token is detected.The code changes are approved.
@@ -120,9 +120,8 @@ export const UserPropsProvider: FC = ({ children }) => { | |||
}, [token, refetchUserData]); | |||
|
|||
React.useEffect(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As impersonationModeOn
is a dependency, and we are calling setIsImpersonationModeOn
within the useEffect, unnecessary calls will be made to setIsImpersonationModeOn
(at least 2 times while loading impersonation mode initially from local storage), and in the worst case we could end up in a loop.
Could we change this to:
React.useEffect(() => {
const impersonationData = localStorage.getItem('impersonationData');
if (impersonationData !== null && !isImpersonationModeOn) {
setIsImpersonationModeOn(true);
} else if (impersonationData === null && isImpersonationModeOn) {
setIsImpersonationModeOn(false);
}
}, []);
Would removing the dependency cause an issue?
@sunilsabatp The issue seems to arise from an expired auth0 token when the app is opened after a while. In this case, To reproduce,
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- src/features/common/Layout/UserPropsContext.tsx (2 hunks)
Files skipped from review as they are similar to previous changes (1)
- src/features/common/Layout/UserPropsContext.tsx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- src/features/common/Layout/UserPropsContext.tsx (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- src/features/common/Layout/UserPropsContext.tsx