修复 修改名称 无token不退出登录的逻辑
This commit is contained in:
@@ -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<UserStorage>().deleteUser();
|
||||
GetIt.I<AuthCubit>().logout();
|
||||
});
|
||||
return Left(DeviceFailure.serverError(message: '登录状态失效,请重新登录'));
|
||||
}
|
||||
final headers = {
|
||||
'Content-Type': 'application/json',
|
||||
|
||||
Reference in New Issue
Block a user