From 612b128f7ad01dc6a204a6639b2b7cf7a3585e5a Mon Sep 17 00:00:00 2001 From: mmc <1556375442@qq.com> Date: Thu, 5 Mar 2026 09:22:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=90=8D=E7=A7=B0=20=20=E6=97=A0token=E4=B8=8D=E9=80=80?= =?UTF-8?q?=E5=87=BA=E7=99=BB=E5=BD=95=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../my/presentation/web_view/user_info_pages.dart | 7 ++++++- lib/features/my/repository/my_repository_impl.dart | 13 +++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/features/my/presentation/web_view/user_info_pages.dart b/lib/features/my/presentation/web_view/user_info_pages.dart index 6dbbd3de..60525c0a 100644 --- a/lib/features/my/presentation/web_view/user_info_pages.dart +++ b/lib/features/my/presentation/web_view/user_info_pages.dart @@ -1,6 +1,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_webrtc/flutter_webrtc.dart'; +import 'package:go_router/go_router.dart'; +import 'package:maibu_satabot_v2/core/router/route_paths.dart'; import 'package:maibu_satabot_v2/features/devices/presentation/bloc/devices_cubit.dart'; import 'package:maibu_satabot_v2/features/my/presentation/bloc/my_cubit.dart'; import 'package:maibu_satabot_v2/features/my/presentation/bloc/my_state.dart'; @@ -67,6 +69,9 @@ class _UserInfoCardState extends State { child: BlocBuilder( builder: (context, myState) { final cubit = context.read(); + if (myState.errorMessage == '登录状态失效,请重新登录') { + context.go(RoutePaths.login); + } return Padding( padding: EdgeInsets.only(left: 16, right: 16, top: 20, bottom: MediaQuery.of(context).viewInsets.bottom + 80), @@ -150,7 +155,7 @@ class _UserInfoCardState extends State { // 提交新昵称的业务逻辑 Future _submitNewNickname(BuildContext context) async { final newNickname = _nicknameController.text.trim(); - if (newNickname.isEmpty ) { + if (newNickname.isEmpty) { Navigator.pop(context); return; } diff --git a/lib/features/my/repository/my_repository_impl.dart b/lib/features/my/repository/my_repository_impl.dart index 66c11ba9..8cba6b2f 100644 --- a/lib/features/my/repository/my_repository_impl.dart +++ b/lib/features/my/repository/my_repository_impl.dart @@ -1,6 +1,9 @@ import 'dart:math'; import 'package:fpdart/fpdart.dart'; +import 'package:get_it/get_it.dart'; import 'package:http/http.dart' as http; +import 'package:maibu_satabot_v2/core/router/route_paths.dart'; +import 'package:maibu_satabot_v2/features/auth/presentation/bloc/auth_cubit.dart'; import 'package:maibu_satabot_v2/features/my/repository/my_repository.dart'; import 'dart:convert'; @@ -27,8 +30,14 @@ class MyRepositoryImpl implements MyRepository { // 补充:从 UserStorage 获取 token(接口通常需要认证) final token = await _getToken(); - if(token!.isEmpty){ - + // 1. Token 为空/无效:返回专属错误 + if (token == null || token.isEmpty) { + // 异步执行登出(不阻塞当前方法返回) + Future.microtask(() async { + await GetIt.I().deleteUser(); + GetIt.I().logout(); + }); + return Left(DeviceFailure.serverError(message: '登录状态失效,请重新登录')); } final headers = { 'Content-Type': 'application/json',