# Flutter refreshing the tokens

**URL:** <https://community.auth0.com/t/flutter-refreshing-the-tokens/104121>\
**Category:** Get Help\
**Tags:** reusable-refresh-tokens, sessions\
**Created:** [April 4, 2023, 6:26pm UTC](https://community.auth0.com/t/flutter-refreshing-the-tokens/104121 "2023-04-04T18:26:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![milojevic.nemanja95](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@milojevic.nemanja95](https://community.auth0.com/u/milojevic.nemanja95)\
**Post date:** [April 4, 2023, 6:26pm UTC](https://community.auth0.com/t/flutter-refreshing-the-tokens/104121/1 "2023-04-04T18:26:26Z")

</div>

Hello, I’m using the [auth0\_flutter](https://pub.dev/packages/auth0_flutter) package, and I’m having trouble with the credentials manager. In the documentation it clearly states that the `credentials()` method “Retrieves the credentials from the storage and refreshes them if they have already expired.” ([docs](https://pub.dev/documentation/auth0_flutter/latest/auth0_flutter/DefaultCredentialsManager/credentials.html)), but I can’t seem to get it working. I’m receiving the `refresh_token` after authenticating and I have set token duration to 30s. Also, I have set the token rotation. But when I invoke the `credentials()` I get the same tokens back.

So, am I misunderstanding the `credentials()` method? Is it supposed to renew the tokens using the `refresh_token` or not?

My code:

```auto
Future<void> login() async {
    await auth0.webAuthentication(scheme: dotenv.env["AUTH0_SCOPE"]!).login();
    _isLoggedIn = true;
    notifyListeners();
  }

  Future<void> logout() async {
    await auth0.webAuthentication(scheme: dotenv.env["AUTH0_SCOPE"]!).logout();
    _isLoggedIn = false;
    notifyListeners();
  }

  Future<bool> isUserLoggedIn() async {
    final loggedIn = await auth0.credentialsManager.hasValidCredentials();
    if (loggedIn) {
      final credentials = await auth0.credentialsManager.credentials();
      print(credentials.expiresAt);
      print(credentials.idToken);
      print(credentials.accessToken);
      print(credentials.refreshToken);
    }
    if (loggedIn) {
      _isLoggedIn = true;

      return true;
    }

    return false;
  }

```

The `isUserLoggedIn()` is used only when the app starts to check if the user is already logged in.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [April 5, 2023, 8:51am UTC](https://community.auth0.com/t/flutter-refreshing-the-tokens/104121/2 "2023-04-05T08:51:43Z")

</div>

Hey there!

In order to handle that most effectively can I ask you to raise it as a GitHub issue here in the repo:

> **[Issues · auth0/auth0-flutter](https://github.com/auth0/auth0-flutter/issues)**
>
> Auth0 SDK for Flutter. Contribute to auth0/auth0-flutter development by creating an account on GitHub.

so we can work on that directly with the repo maintainers. Once you have a link to it you can share it here so we can ping them. Thank you!

---

<div class="post-metadata">

**Author:** ![milojevic.nemanja95](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@milojevic.nemanja95](https://community.auth0.com/u/milojevic.nemanja95)\
**Post date:** [April 5, 2023, 5:35pm UTC](https://community.auth0.com/t/flutter-refreshing-the-tokens/104121/3 "2023-04-05T17:35:21Z")

</div>

Thanks for the answer. Here’s the issue link: [Issue with refreshing the token using credentials manager · Issue #234 · auth0/auth0-flutter · GitHub](https://github.com/auth0/auth0-flutter/issues/234)

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [April 6, 2023, 7:56am UTC](https://community.auth0.com/t/flutter-refreshing-the-tokens/104121/4 "2023-04-06T07:56:45Z")

</div>

Perfect! I’ll ping the repo maintainers in a few minutes!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [April 20, 2023, 7:57am UTC](https://community.auth0.com/t/flutter-refreshing-the-tokens/104121/5 "2023-04-20T07:57:21Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
