소스 검색

[logout] clear local storage on api success only

Neeraj Gupta 4 년 전
부모
커밋
f685289468
3개의 변경된 파일24개의 추가작업 그리고 19개의 파일을 삭제
  1. 0 1
      lib/core/configuration.dart
  2. 21 11
      lib/services/user_service.dart
  3. 3 7
      lib/ui/settings/account_section_widget.dart

+ 0 - 1
lib/core/configuration.dart

@@ -104,7 +104,6 @@ class Configuration {
     }
     await _preferences.clear();
     await _secureStorage.deleteAll();
-    await UserService.instance.logout();
     _key = null;
     _cachedToken = null;
     _secretKey = null;

+ 21 - 11
lib/services/user_service.dart

@@ -90,18 +90,28 @@ class UserService {
     }
   }
 
-  Future<bool> logout() async {
+  Future<void> logout(BuildContext context) async {
+    final dialog = createProgressDialog(context, "logging out...");
+    await dialog.show();
     try {
-      final response = await _dio.post(
-        _config.getHttpEndpoint() + "/users/logout",
-        options: Options(headers: {
-          "X-Auth-Token": _config.getToken(),
-        }),
-      );
-      return response != null && response.statusCode == 200;
-    } on DioError catch (e) {
-      _logger.warning(e);
-      return false;
+      final response =
+          await _dio.post(_config.getHttpEndpoint() + "/users/logout",
+              options: Options(
+                headers: {
+                  "X-Auth-Token": _config.getToken(),
+                },
+              ));
+      if (response != null && response.statusCode == 200) {
+        await Configuration.instance.logout();
+        await dialog.hide();
+        Navigator.of(context).popUntil((route) => route.isFirst);
+      } else {
+        throw new Exception("log out action failed");
+      }
+    } catch (e) {
+      _logger.severe(e);
+      await dialog.hide();
+      showGenericErrorDialog(context);
     }
   }
 

+ 3 - 7
lib/ui/settings/account_section_widget.dart

@@ -3,6 +3,7 @@ import 'dart:io';
 import 'package:flutter/material.dart';
 import 'package:photos/core/configuration.dart';
 import 'package:photos/services/billing_service.dart';
+import 'package:photos/services/user_service.dart';
 import 'package:photos/ui/loading_widget.dart';
 import 'package:photos/ui/settings/settings_section_title.dart';
 import 'package:photos/ui/settings/settings_text_item.dart';
@@ -96,13 +97,8 @@ class AccountSectionWidgetState extends State<AccountSectionWidget> {
                       ),
                     ),
                     onPressed: () async {
-                      Navigator.of(context, rootNavigator: true).pop('dialog');
-                      final dialog =
-                          createProgressDialog(context, "logging out...");
-                      await dialog.show();
-                      await Configuration.instance.logout();
-                      await dialog.hide();
-                      Navigator.of(context).popUntil((route) => route.isFirst);
+                       Navigator.of(context, rootNavigator: true).pop('dialog');
+                       await UserService.instance.logout(context);
                     },
                   ),
                 ],