-暂提交-bug未处理
This commit is contained in:
@@ -68,25 +68,12 @@ class AuthCubit extends Cubit<AuthState> {
|
||||
|
||||
/// 当 HTTP 登录/注册成功后调用
|
||||
Future<void> loginSuccess(UserEntity user) async {
|
||||
// 🔥 关键修复:先立即更新状态,触发 GoRouter redirect
|
||||
await storage.saveUser(user);
|
||||
await tcp.connect(host: TCPConsts.TCP_IP, port: TCPConsts.TCP_PORT);
|
||||
// await _authTcpDatasource.sendAuthPacket(); //包括发送认证包和获取列表和切换函数
|
||||
//tcp.startHeartbeat(interval: const Duration(seconds: 4)); //启动心跳
|
||||
appCubit.setAuth(user);
|
||||
emit(AuthAuthenticated(user));
|
||||
|
||||
// 然后异步执行其他操作(不阻塞主流程)
|
||||
_performPostLoginTasks(user);
|
||||
}
|
||||
|
||||
/// 登录后后台任务(不阻塞主流程)
|
||||
Future<void> _performPostLoginTasks(UserEntity user) async {
|
||||
try {
|
||||
await storage.saveUser(user);
|
||||
await tcp.connect(host: TCPConsts.TCP_IP, port: TCPConsts.TCP_PORT);
|
||||
// await _authTcpDatasource.sendAuthPacket();
|
||||
// tcp.startHeartbeat(interval: const Duration(seconds: 4));
|
||||
} catch (e) {
|
||||
_logger.logWithLevel('[AUTH] 登录后任务失败: $e', level: 'ERROR');
|
||||
// 不影响已登录状态,只是记录错误
|
||||
}
|
||||
}
|
||||
|
||||
/// 退出登录 (主动或被动)
|
||||
|
||||
Reference in New Issue
Block a user