Skip to content

Commit

Permalink
fix data on reboot
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaCoduriV committed Sep 3, 2022
1 parent 294ff11 commit 4657553
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Future<void> setup() async {
clientApi: FirebaseUser(FirebaseFirestore.instance),
),
);
await GetIt.I.get<AuthProvider>().init();
}

void main() async {
Expand Down
13 changes: 12 additions & 1 deletion lib/provider/auth_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ class AuthProvider extends ChangeNotifier {
: _auth = auth,
_userApi = clientApi;

Future<void> init() async {
if (isConnected()) {
final values = await Future.wait([
fetchClient(),
_auth.isDietitian(),
]);

_isAdmin = values[1] as bool;
}
}

bool get isAdmin => _isAdmin;

User? get user => _client;
Expand All @@ -33,7 +44,7 @@ class AuthProvider extends ChangeNotifier {
//await _auth.signIn(email: "[email protected]", password: 'crepes');
_isAdmin = await _auth.isDietitian();
if (isConnected) {
fetchClient();
await fetchClient();
}

notifyListeners();
Expand Down

0 comments on commit 4657553

Please sign in to comment.