Skip to content
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(lib-classifier): refresh expired bearer tokens #6604

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

eatyourgreens
Copy link
Contributor

@eatyourgreens eatyourgreens commented Jan 8, 2025

Fix usePanoptesAuth hook to refresh expired bearer tokens in the classifier. Fixes a bug where Quick Talk stops working once your bearer token expires.

Please request review from @zooniverse/frontend team or an individual member of that team.

Package

  • lib-classifier

Linked Issue and/or Talk Post

How to Review

The original issue (#6594) happens if you leave the classifier open long enough for your bearer token to expire, so you might need to open the classifier in a tab and leave it for a couple of hours. With the changes here, an expired token should always be refreshed, as long as you don't allow your Panoptes refresh token to expire. I think refresh tokens are good for up to 2 weeks.

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

  • Tests are passing locally and on Github
  • Documentation is up to date and changelog has been updated if appropriate
  • You can yarn panic && yarn bootstrap or docker-compose up --build and FEM works as expected
  • FEM works in all major desktop browsers: Firefox, Chrome, Edge, Safari (Use Browserstack account as needed)
  • FEM works in a mobile browser

General UX

Example Staging Project: i-fancy-cats

  • All pages of a FEM project load: Home Page, Classify Page, and About Pages
  • Can submit a classification
  • Can sign-in and sign-out
  • The component is accessible

Bug Fix

  • The PR creator has listed user actions to use when testing if bug is fixed
  • The bug is fixed
  • Unit tests are added or updated

@coveralls
Copy link

coveralls commented Jan 8, 2025

Coverage Status

coverage: 75.621% (-0.004%) from 75.625%
when pulling d296240 on eatyourgreens:fix-quick-talk
into a7d4db0 on zooniverse:master.

@eatyourgreens eatyourgreens force-pushed the fix-quick-talk branch 2 times, most recently from 56e4739 to 4c9d54b Compare January 17, 2025 10:35
Comment on lines -12 to -14
useEffect(function onUserChange() {
checkAuth()
}, [authClient, userID])
Copy link
Contributor Author

@eatyourgreens eatyourgreens Jan 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original bug happens because this hook stores your bearer token in component state and reuses it forever, even after it has expired. The token should be checked (by running checkAuth()) every time that it's used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General tip for reviewing React components: whenever you see useEffect it has probably introduced a subtle bug.

Fix `usePanoptesAuth` hook to refresh expired bearer tokens in the classifier. Fixes a bug where Quick Talk stops working once your bearer token expires.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to create a new discussion from Quick Talk
2 participants