-
Notifications
You must be signed in to change notification settings - Fork 14.1k
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
feat: On window focus, redirect to login if the user has been logged out #18773
Conversation
b02c381
to
d99a5c0
Compare
openapi_spec_component_schemas = (UserResponseSchema,) | ||
|
||
@expose("/", methods=["GET"]) | ||
@safe |
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 didn't want to add a permission for this API, because it should be callable by any user. @dpgaspar this is safe, yeah?
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 think this getMe API is great, as it may have plenty o' uses (e.g. when we revisit the Profile design). But just to say it "out loud" we could also implement a GET /time API or something as a lightweight, security-irrelevant API, if performance or security ever become a factor here.
@@ -81,6 +81,7 @@ def bootstrap_user_data(user: User, include_perms: bool = False) -> Dict[str, An | |||
"lastName": user.last_name, | |||
"userId": user.id, | |||
"isActive": user.is_active, | |||
"isAnonymous": user.is_anonymous, |
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.
Added is_anonymous
here for consistency
if (bootstrapData.user?.isActive) { | ||
document.addEventListener('visibilitychange', () => { | ||
// we only care about the tab becoming visible, not vice versa | ||
if (document.visibilityState !== 'visible') return; |
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.
Do we want to do this every time the user changes a tab (even if there are two Superset tabs), or maybe not more often than every x seconds?
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.
It's a pretty cheap endpoint to call, and most people probably aren't changing tabs often enough to be an issue. I think this is fine.
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.
Agree with @suddjian , but good callout — I always appreciate a performance-oriented mindset
Codecov Report
@@ Coverage Diff @@
## master #18773 +/- ##
==========================================
+ Coverage 66.31% 66.33% +0.01%
==========================================
Files 1620 1622 +2
Lines 63080 63114 +34
Branches 6370 6372 +2
==========================================
+ Hits 41833 41865 +32
- Misses 19591 19592 +1
- Partials 1656 1657 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
export let bootstrapData: any; | ||
export let bootstrapData: { | ||
user?: User | undefined; | ||
common?: any; |
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.
Le sigh... not the concern of this PR by any means, but maybe we should make backlog ticket(s) to add types for common/config.
/testenv up |
@rusackas Ephemeral environment spinning up at http://18.236.157.164:8080. Credentials are |
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.
Curious what feedback @dpgaspar would have on the backend/security issue, but the changes look good to me, and it sure seems like it does the trick in testing!
401: | ||
$ref: '#/components/responses/401' | ||
""" | ||
if g.user is None or g.user.is_anonymous: |
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 am wondering if returning 401 for anonymous users won't effectively make read-only access impossible for them?
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 ok I see what you are doing in the frontend to avoid this being requested for anon users bootstrapData.user?.isActive
. I am thinking if this might confuse someone else when using this endpoint in some other places and if we might end up in that problem, but I might just be overthinking it right now.
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.
This endpoint is only called if the user isActive
, which is synonymous with !isAnonymous
Ephemeral environment shutdown and build artifacts deleted. |
SUMMARY
If you have Superset open in the background and your session expires, the frontend will still display the logged-in state until the next request happens to fire, jarringly sending you all of a sudden to the login page.
Until now.
This code listens for the document's
visibilitychange
event. When the tab is focused, a request is made to the new/api/v1/me/
endpoint, which returns 401 if the user is not logged in. The SupersetClient detects the 401 and sends the user to the login page.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Screen.Recording.2022-02-16.at.4.58.09.PM.mov
TESTING INSTRUCTIONS
Open Superset in two tabs. Log out of one tab. Switch to the other tab. It will immediately redirect to the login page.
ADDITIONAL INFORMATION