Force cookie to be saved if not (#5254)

This commit is contained in:
Edouard Marquez
2024-05-17 08:57:18 +02:00
committed by GitHub
parent 1a6c488827
commit fd9633c05a
2 changed files with 13 additions and 9 deletions

View File

@ -1,3 +1,5 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:openfoodfacts/openfoodfacts.dart';
@ -110,14 +112,16 @@ class UserManagementProvider with ChangeNotifier {
password: user.password,
),
);
switch (loginResult.type) {
case LoginResultType.successful:
case LoginResultType.serverIssue:
case LoginResultType.exception:
return;
case LoginResultType.unsuccessful:
// TODO(m123): Notify the user
await logout();
if (loginResult.type == LoginResultType.unsuccessful) {
// TODO(m123): Notify the user
await logout();
return;
}
/// Save the cookie if necessary
if (user.cookie == null && loginResult.user?.cookie != null) {
putUser(loginResult.user!);
}
}
}

View File

@ -136,6 +136,7 @@ Future<bool> _init1() async {
),
daoString: DaoString(_localDatabase),
);
ProductQuery.setQueryType(_userPreferences);
UserManagementProvider().checkUserLoginValidity();
await AnalyticsHelper.linkPreferences(_userPreferences);
@ -144,7 +145,6 @@ Future<bool> _init1() async {
_themeProvider = ThemeProvider(_userPreferences);
_colorProvider = ColorProvider(_userPreferences);
_textContrastProvider = TextContrastProvider(_userPreferences);
ProductQuery.setQueryType(_userPreferences);
await CameraHelper.init();
await ProductQuery.setUuid(_localDatabase);