修复无限登录的问题

hmxc
小赖 4 years ago
parent f35500f47f
commit 051c8f6f97

@ -21,6 +21,9 @@ class _Auth {
////退app
String get login => '/login/loginSMSUser';
////退退
String get logout => '/user/signOut';
}
class _User {

@ -2,6 +2,7 @@
import 'dart:io';
// Flutter imports:
import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/material.dart';
// Project imports:
@ -24,13 +25,9 @@ class UserProvider extends ChangeNotifier {
///
Future setLogin(int token) async {
_isLogin = true;
NetUtil()
.dio
.options
.headers
.putIfAbsent('butlerApp-admin-token', () => token);
HiveStore.appBox.put('token', token);
HiveStore.appBox.put('login', true);
NetUtil().auth(token);
await HiveStore.appBox.put('token', token);
await HiveStore.appBox.put('login', true);
_profileModel = await updateProfile();
_infoModel = await updateUserInfo();
// await setCurrentHouse((_userDetailModel?.estateNames?.isEmpty ?? true)
@ -62,9 +59,12 @@ class UserProvider extends ChangeNotifier {
}
///
logout() {
logout() async {
await NetUtil().get(API.auth.logout, showMessage: true);
NetUtil().logout();
_isLogin = false;
HiveStore.appBox.delete('token');
await HiveStore.appBox.delete('token');
await HiveStore.appBox.put('login', false);
notifyListeners();
}

@ -37,6 +37,7 @@ class NetUtil {
onRequest: (RequestOptions options) async => options,
onResponse: (Response response) async {
LoggerData.addData(response);
print(response.headers);
return response;
},
onError: (DioError error) async {
@ -47,8 +48,12 @@ class NetUtil {
}
///call auth after login
auth(String token) {
_dio.options.headers.putIfAbsent('Butler-Admin-Token', () => token);
auth(int token) {
_dio.options.headers.putIfAbsent('butlerApp-admin-token', () => token);
}
logout() {
_dio.options.headers.remove('butlerApp-admin-token');
}
/// ## alias of Dio().get

Loading…
Cancel
Save