-
Notifications
You must be signed in to change notification settings - Fork 22
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
fix: use session if exists when doing initial redirect for user #2810
Conversation
src/App.tsx
Outdated
let redirectURL = '/login' | ||
|
||
if (internalUser) { | ||
redirectURL = `/${internalUser.owners![0]?.service}/${ |
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.
if internalUser exists, my assumption here is owners will at least be an empty array
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.
I can't find any reason why that assumption would be bad. but just in case you didn't know how to do optional chaining with array indexing (like I didn't until recently):
redirectURL = `/${internalUser.owners![0]?.service}/${ | |
redirectURL = `/${internalUser.owners?.[0]?.service}/${ |
I think that would be a safer play. Generally try to steer clear of !
myself - it's scary 😰
Bundle ReportChanges will increase total bundle size by 593 bytes ⬆️
|
Bundle ReportChanges will increase total bundle size by 593 bytes ⬆️
|
✅ Deploy preview for gazebo ready!Previews expire after 1 month automatically.
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
✅ All tests successful. No failed tests found Additional details and impacted files@@ Coverage Diff @@
## main #2810 +/- ##
=======================================
Coverage 98.46% 98.46%
=======================================
Files 871 871
Lines 12672 12676 +4
Branches 3389 3373 -16
=======================================
+ Hits 12478 12482 +4
Misses 190 190
Partials 4 4
Continue to review full report in Codecov by Sentry.
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
✅ All tests successful. No failed tests found @@ Coverage Diff @@
## main #2810 +/- ##
=======================================
Coverage 98.46% 98.46%
=======================================
Files 871 871
Lines 12672 12676 +4
Branches 3372 3373 +1
=======================================
+ Hits 12478 12482 +4
Misses 190 190
Partials 4 4
Continue to review full report in Codecov by Sentry.
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
✅ All tests successful. No failed tests found Additional details and impacted files@@ Coverage Diff @@
## main #2810 +/- ##
=====================================
Coverage 98.47 98.47
=====================================
Files 871 871
Lines 12672 12676 +4
Branches 3389 3332 -57
=====================================
+ Hits 12478 12482 +4
Misses 190 190
Partials 4 4
Continue to review full report in Codecov by Sentry.
|
Codecov ReportAll modified and coverable lines are covered by tests ✅ ✅ All tests successful. No failed tests found @@ Coverage Diff @@
## main #2810 +/- ##
=======================================
Coverage ? 98.45%
=======================================
Files ? 870
Lines ? 12636
Branches ? 3380
=======================================
Hits ? 12441
Misses ? 191
Partials ? 4
Continue to review full report in Codecov by Sentry.
|
src/App.tsx
Outdated
|
||
if (internalUser) { | ||
redirectURL = `/${internalUser.owners![0]?.service}/${ | ||
internalUser.owners![0]?.username |
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.
Same suggestion here
internalUser.owners![0]?.username | |
internalUser.owners?.[0]?.username |
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.
You could also toss a lodash isArray
in the if condition, if that's more your style
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.
Yeah, my IDE didn't like that one unfortunately 😭
What do you think about just changing the if statement to
if (internalUser && internalUser.owners) {
redirectURL = `/${internalUser.owners[0]?.service}/${internalUser.owners[0]?.username}`
}
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.
Think its a litttttttle cleaner that way?
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.
oh yea that's great too!
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.
Description
Previously, when a user would come to app.codecov.io or similar, we would route them to the login page more often than not. This was due to us having "naive" redirect logic that was dependent on the existence of a provider to fetch the current user, using the useCurrentUser hook.
More often than not, this would not be the case, and a user would frustratingly end up on the login page even if we already had a session cookie set for them!
My solution then, was to use the useInternalUser() hook (thanks @JerrySentry for the pointer), which will pull the user's session if it exists first and use that to redirect the user. If we have a more specific route, or are able to derive the user's info via the provider and useCurrentUser hook, then we still do that.
There are also a couple other small fixes I baked in here:
Below you can see the behavior before and after. In the before video, we see the sessionId cookie exists, but when we navigate to app.codecov.io we are directed back to the login page. Only when adding 'gh' since I am logged in using my github account am I redirected properly. In the after video there is so such issue :)
Screenshots
BEFORE
Screen.Recording.2024-04-25.at.3.35.08.PM.mov
AFTER
Screen.Recording.2024-04-25.at.3.34.14.PM.mov
Link to Sample Entry
Legal Boilerplate
Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. In 2022 this entity acquired Codecov and as result Sentry is going to need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.