-
Notifications
You must be signed in to change notification settings - Fork 30
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 Panoptes authentication in all packages #4803
Conversation
77bb390
to
0b53f9c
Compare
6040321
to
acc8d1c
Compare
83361af
to
39de677
Compare
67b8745
to
a381330
Compare
8097c25
to
287d5ce
Compare
Adding the 'bug' label to this because it fixes a small bug in the classifier. When you are already logged in, on the Classify page, |
287d5ce
to
9855db1
Compare
You can try out a production build of this branch here: |
2d43bc2
to
39ac06e
Compare
Refactor `usePanoptesUser` to get the current user from the stored Panoptes JWT. Fall back to `auth.checkCurrent()`, which is slower, if we don't have a stored token.
Check Panoptes user state in `ClassifierContainer`. Defer rendering `Classifier` while that check is taking place.
Setting the UPP loading state to 'loading' will unmount the classifier, so avoid that after the page has loaded and the classifier is mounted.
Wait for all user session data to load before rendering the classifier. Refactor the user hooks to use the latest SWR API.
afd5258
to
0f6b5cb
Compare
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.
Looks good! I re-tested each of the Issues tagged here. The dev classifier runs as expected, as do the Zooniverse content pages and classifier storybook.
packages/lib-classifier/src/components/Classifier/Classifier.js
Outdated
Show resolved
Hide resolved
packages/lib-classifier/src/components/Classifier/ClassifierContainer.js
Outdated
Show resolved
Hide resolved
packages/lib-classifier/src/components/Classifier/ClassifierContainer.js
Outdated
Show resolved
Hide resolved
packages/lib-classifier/src/components/Classifier/ClassifierContainer.spec.js
Outdated
Show resolved
Hide resolved
packages/lib-classifier/src/components/Classifier/hooks/usePanoptesUserSession.js
Outdated
Show resolved
Hide resolved
@@ -39,7 +39,7 @@ const SubjectViewer = types | |||
|
|||
.views(self => ({ | |||
get disableImageToolbar () { | |||
const subject = getRoot(self).subjects.active | |||
const subject = tryReference(() => getRoot(self).subjects?.active) |
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.
Question: Just for my understanding, what does the change here implement?
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.
subjects.active
is a reference (it's actually the subject ID.) References should be accessed via tryReference
to avoid errors.
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.
The mock store errored on this line during cleanup, because subjects.active
isn't always a valid reference when the store is destroyed.
Co-authored-by: Delilah C. <[email protected]>
…ntainer.js Co-authored-by: Delilah C. <[email protected]>
Co-authored-by: Delilah C. <[email protected]>
Co-authored-by: Delilah C. <[email protected]>
packages/lib-classifier/src/components/Classifier/ClassifierContainer.spec.js
Outdated
Show resolved
Hide resolved
e42ab19
to
df1e425
Compare
df1e425
to
be05d50
Compare
Refactor
usePanoptesUser
to get the current user from the stored Panoptes JWT (#4766.) Fall back toauth.checkCurrent()
, which gets a new session and token from the Panoptes API, if we don't have a stored token.Refactor the classifier to authenticate in
ClassifierContainer
, waiting until sign-in is complete and all user data has loaded before rendering theClassifier
component (#4845 and #4875.) Move all the workflow validation up toClassifierContainer
, so that we validate the workflow ID (from the URL) when the user has loaded, then pass down null toClassifier
if they don't have permission to view that workflow.Test
ClassifierContainer
, checking that:/subjects/queued
is only called once.Fix a bug, in the project app, where updating the project user in the project app's store will unmount and mount the classifier (#4946.)
Fix a bug where a
project_roles
request is continually made (closes #4975).The
Classifier
component uses MobX observable data, but isn't wrapped inobserver
, so I've also fixed that here.Please request review from
@zooniverse/frontend
team or an individual member of that team.Package
Linked Issue and/or Talk Post
How to Review
This PR reflects on the Panoptes JSON Web Token to get the logged-in user for the project app, the content pages app and the classifier, which should be faster than pinging the API for the current user session and won’t ask Panoptes OAuth to generate a new token (zooniverse/panoptes-javascript-client#53.) If there's no stored token yet, it falls back to
auth.checkCurrent()
, which is currently used for all user checks.You should be able to use any project, logged-in or not, and continue to use Admin Mode without any changes to the app's behaviour.
On page load, there should only be one request to
/api/me
to get the user resource.Subjects should only be fetched once, with your access token, after you log in (#4875.)
Apps will still lose your stored session when they unload eg. when going from PFE to FEM on the same origin, or when going from the project app to the content pages app. That can be tested in staging, on the
https://frontend.preview.zooniverse.org
origin, after this PR merges.Checklist
PR Creator - Please cater the checklist to fit the review needed for your code changes.
PR Reviewer - Use the checklist during your review. Each point should be checkmarked or discussed before PR approval.
General
yarn panic && yarn bootstrap
ordocker-compose up --build
and FEM works as expectedGeneral UX
Example Staging Project: i-fancy-cats
Refactoring