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

token returns null when awaited right after initializing #70

Closed
jteague9 opened this issue Jul 19, 2022 · 3 comments
Closed

token returns null when awaited right after initializing #70

jteague9 opened this issue Jul 19, 2022 · 3 comments

Comments

@jteague9
Copy link

Code to reproduce:

import 'package:fresh/fresh.dart';

class InMemoryDelayed extends InMemoryTokenStorage<String> {
  @override
  Future<String?> read() async {
    await Future<dynamic>.delayed(Duration.zero);
    return super.read();
  }
}

class Foo with FreshMixin<String> {
  Foo(InMemoryDelayed tokenStorage) {
    this.tokenStorage = tokenStorage;
  }
}

void main() async {
  var storage = InMemoryDelayed();
  await storage.write('token');
  var foo = Foo(storage);
  var token = await foo.token;
  print(token); // prints null, but should print 'token'
}

The token method is not waiting for the first read from storage to complete.

https://github.com/felangel/fresh/blob/master/packages/fresh/lib/src/fresh.dart#L110 this line can be changed to
await authenticationStatus.firstWhere((status) => status != AuthenticationStatus.initial);

I can put up a PR if you think this fix is appropriate.

lulupointu added a commit to lulupointu/fresh that referenced this issue Feb 14, 2024
…icated) before returning the token

This fix allows initial token to be fetched asynchronously. See felangel#70 for a snippet describing the issue
@lyio
Copy link

lyio commented May 16, 2024

I ran into the same problem yesterday.

@vasilich6107
Copy link

Hey @felangel
Could you take a look at the issue and PR?
Probably it's just matter of pressing of merge button

@felangel
Copy link
Owner

Closed by #96

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

No branches or pull requests

4 participants