directus_api_manager icon indicating copy to clipboard operation
directus_api_manager copied to clipboard

Token expiration problem

Open armanhadifatah opened this issue 1 year ago • 4 comments

I created authentication like this

  DirectusApiManager directusApiManager = DirectusApiManager(
      baseURL: "https://control.seedkurdistan.org",
      saveRefreshTokenCallback: (refreshToken) async {
// Create storage
        var storage = ref.read(flutterSecureStorageProvider);
        await storage.write(key: refreshStorage, value: refreshToken);
      },
      loadRefreshTokenCallback: () async {
        var storage = ref.read(flutterSecureStorageProvider);
        var token = await storage.read(key: refreshStorage);
        // now if token is expired, we can load it from storage
        return token;
      });

but still when the token expire it will not automatically use the new one the app crash but if i close and open the app work again

armanhadifatah avatar Apr 24 '24 10:04 armanhadifatah

Hello @armanhadifatah ! Could you provide more information about the crash your are mentioning ?

maxbritto avatar Apr 26 '24 08:04 maxbritto

Hello @armanhadifatah ! Could you provide more information about the crash your are mentioning ?

After a while I get error that token expired , but with a refresh its again ok and no error

armanhadifatah avatar Apr 28 '24 09:04 armanhadifatah

My guess is that you might have an issue with your saving/loading of the token. Maybe this doesn't work as expected since I do not know this dependency : ref.read(flutterSecureStorageProvider);

I would love to help more but you need to provide more details : the exact error displayed with stack trace would be a good start :)

maxbritto avatar Apr 28 '24 17:04 maxbritto

My guess is that you might have an issue with your saving/loading of the token. Maybe this doesn't work as expected since I do not know this dependency : ref.read(flutterSecureStorageProvider);

I would love to help more but you need to provide more details : the exact error displayed with stack trace would be a good start :)

Thanks for your reply could you please give me the best way how to do it ?

armanhadifatah avatar Apr 28 '24 18:04 armanhadifatah