Closed jteague9 closed 4 months ago
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.
token
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);
await authenticationStatus.firstWhere((status) => status != AuthenticationStatus.initial);
I can put up a PR if you think this fix is appropriate.
I ran into the same problem yesterday.
Hey @felangel Could you take a look at the issue and PR? Probably it's just matter of pressing of merge button
merge
Closed by #96
Code to reproduce:
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.