Browse Source

fix(account): 在登出时清理用户会话数据

添加User.clearUserSession()调用以确保用户登出时完全清理会话数据
同时在蓝牙管理器中增加登录状态检查,防止未登录时跳转配对页面
newdev_shunjiawei
lxm 10 months ago
parent
commit
6ec7984b0d
  1. 3
      lib/data/services/account_service.dart
  2. 15
      lib/data/services/bluetooth_manager.dart

3
lib/data/services/account_service.dart

@ -7,6 +7,7 @@ import '../../modules/login/controllers/facebookLogin.dart';
import '../services/network/api.dart';
import 'db/database_helper.dart';
import 'meeting/meeting_task_service.dart';
import '../../data/models/user_Info.dart';
/// 账号管理服务
///
@ -33,6 +34,7 @@ class AccountService extends GetxService {
await _storage.write("logintoken", null);
await _storage.write("user_info", null);
await _storage.write("local_avatar", null);
User.clearUserSession();
logger.d('用户数据清理成功');
return true;
} catch (e) {
@ -45,6 +47,7 @@ class AccountService extends GetxService {
// 清理所有用户数据
try {
await _storage.erase();
User.clearUserSession();
logger.d('所有用户数据清理成功');
return true;
} catch (e) {

15
lib/data/services/bluetooth_manager.dart

@ -1,6 +1,7 @@
import 'dart:async';
import 'package:get/get.dart';
import 'package:classic_bluetooth/classic_bluetooth.dart';
import 'package:get_storage/get_storage.dart';
import '../../core/utils/logger.dart';
import '../../routes/app_routes.dart';
import 'ble_manager.dart';
@ -21,6 +22,7 @@ class BluetoothManager extends GetxService {
final Rx<BluetoothDevice?> currentDeviceRx = Rx<BluetoothDevice?>(null);
BluetoothDevice? get currentDevice => currentDeviceRx.value;
final BleManager _bleManager = Get.find<BleManager>();
final GetStorage _storage = GetStorage();
// 订阅
StreamSubscription<BluetoothEvent>? _bluetoothSubscription;
@ -76,7 +78,8 @@ class BluetoothManager extends GetxService {
currentDeviceRx.value = newDevice;
// 检查当前是否在OTA升级界面,如果是则不跳转
if (!_isInOtaUpgradePage() &&
if (_isLoggedIn() &&
!_isInOtaUpgradePage() &&
!_bleManager.isConnected &&
Get.currentRoute != Routes.pairing) {
Get.toNamed(Routes.pairing, arguments: newDevice);
@ -161,4 +164,14 @@ class BluetoothManager extends GetxService {
return false;
}
}
/// 是否已登录
bool _isLoggedIn() {
try {
final token = _storage.read('logintoken');
return token != null && token is String && token.isNotEmpty;
} catch (e) {
return false;
}
}
}

Loading…
Cancel
Save