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

🐛 BUG - Reactions not working (Expired JWT token) #1340

Open
1 of 2 tasks
JackDevAU opened this issue May 10, 2024 · 3 comments
Open
1 of 2 tasks

🐛 BUG - Reactions not working (Expired JWT token) #1340

JackDevAU opened this issue May 10, 2024 · 3 comments
Assignees
Labels
Type: Bug A problem with existing functionality

Comments

@JackDevAU
Copy link
Member

JackDevAU commented May 10, 2024

Cc: @bradystroud @KristenHu @Aibono1225 @adamcogan @drwharris

Hi Team,

("Copying" from email - RE: Update Rule “autonomy-mastery-and-purpose/rule” #8469)

Describe the Bug

So, I did some digging and found that if you already have something favourited you can’t add another. If you have nothing favourited, you can add something. The issue seems to be an API call returning a 401 as you can see in the following screen shot

Upon further investigation, signing out and signing back in seems to allow you to react to rules again!
This would likely mean the error is to do with an expired user token.

To Reproduce

Steps to reproduce the behavior:

  1. Go to https://www.ssw.com.au/rules/fundamentals-of-prompt-engineering/
  2. Be logged into Rules
  3. Scroll down to the bottom and React
  4. See reaction reset

Expected Behavior

  • A reaction should increment if you haven't reacted to it before!
  • When a user has an expired JWT token - we should refresh it or log them out

Tasks

  • Investigate
  • Fix

Screenshots

Image

Figure: Error that occurs when you try and add a favourite if you already have one.

Thanks!

@JackDevAU JackDevAU added the Type: Bug A problem with existing functionality label May 10, 2024
@KristenHu
Copy link
Member

KristenHu commented May 14, 2024

Update: I've tried to add the function to refresh token, but I cannot reproduce the bug to test currently.

@JackDevAU JackDevAU assigned Aibono1225 and unassigned KristenHu May 21, 2024
@Aibono1225
Copy link
Member

Update:
The Rules Functions use auth0's id_token for authentication.

I tested the issue locally with my own auth0 account. After enabling refresh token and waiting for the original id_token to expire, I successfully obtained a new id_token using the /oauth/token API. With this new token, I was able to call the Reactions API successfully.

Image

However there is a potential issue with this approach. The /oauth/token API only provides the new id_token and doesn't update the token claims stored in local storage. This means that once the old token expires, we need to obtain the new id_token every time we call a Rules API, which doesn't seem to be a good practice.

Image
Figure: The claims are not updated, so we will still get an expired token if we use const claims = await getIdTokenClaims();

@Aibono1225
Copy link
Member

After some investigation, the getAccessTokenSilently method seems to be able to refresh id_token in local storage when the cacheMode is set to 'off'

    const token = await getAccessTokenSilently({
      audience: 'xxx',
      scope: 'openid profile email offline_access',
      grant_type: 'refresh_token',
      ignoreCache: true,
      cacheMode: 'off',
    });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug A problem with existing functionality
Projects
None yet
Development

No branches or pull requests

3 participants