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: getUserInfo not working when the access token expires and is refreshed #5970

Closed
Anotherjez opened this issue Jun 2, 2024 · 3 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@Anotherjez
Copy link

Anotherjez commented Jun 2, 2024

Describe the bug

I'm developing an app in Flutter and I've noticed that my beta users have to log in every 1 hour or less, which is not ideal. I use Logto and Mongodb authenticating the users by JWT.

To make the session more persistent I created a function that checks if the user is authenticated, first I request the access token and then the idToken, if the idToken is not null then it authenticates the user silently but if it is null then it returns the user to the login screen.

await logtoClient.getAccessToken(); // To refresh the access token
final String? idtoken = await logtoClient.idToken; // Used to authenticate user in realm (mongodb) by JWT
print(await logtoClient.isAuthenticated); // true

When I print this it returns the access token and the idToken but immediately I run getUserInfo() it gives me an error.

LogtoUserInfoResponse user = await logtoClient.getUserInfo();

Error:

LogtoAuthException(LogtoAuthExceptions.authenticationError): not_authenticated

Expected behavior

Run the function getUserInfo() to return the user info that is necessary for the app functionality.

You should not get this error if the access token is refreshed and valid and also if the “isAuthenticated” method returns true.

According to the code of the function getUserInfo(), it throws this error when the access token is null, which does not make sense if before executing this function it returns me the valid and refreshed access token, and also returns me the idToken.

How to reproduce?

(Only tested on Android)

  • Wait for the access token to expire after authenticating the user.
  • Open the app and run the function that checks if the user is authenticated.
  • Run await logtoClient.getAccessToken();
  • Get the idToken final String? idtoken = await logtoClient.idToken;
  • Get the user info await logtoClient.getUserInfo();

Context

  • logto_dart_sdk: ^1.2.0

Screenshots

image

@Anotherjez Anotherjez added the bug Something isn't working label Jun 2, 2024
@simeng-li simeng-li self-assigned this Jun 3, 2024
@simeng-li
Copy link
Contributor

@Anotherjez thx for the report. There is a bug in the getUserInfo method. It should fetch the new access token automatically.

@simeng-li
Copy link
Contributor

@Anotherjez the bug has been fixed in the latest release v2.0.1. Please check

@Anotherjez
Copy link
Author

@Anotherjez the bug has been fixed in the latest release v2.0.1. Please check

Now is working fine, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

2 participants