修复personal退出登录误弹登录过期弹窗

This commit is contained in:
2026-10-10 10:12:11 +08:00
parent 167229371f
commit dc006c2935

View File

@@ -40,12 +40,17 @@ class DioClient {
if (response.data is Map<String, dynamic>) { if (response.data is Map<String, dynamic>) {
final code = response.data['code']; final code = response.data['code'];
if (code == 401 || code == 403) { if (code == 401 || code == 403) {
print( // 🔥 仅在当前确实处于登录态时,才把 401 当作「登录过期」弹窗。
'>>> [DIO] 🚨🚨🚨 收到业务错误码 $code,触发 Token 过期处理!URL: ${response.requestOptions.uri},时间: ${DateTime.now()}', // 退出登录过程中 AppUserCubit.user 已被清为 null,此时残留/竞态请求
); // 返回的 401 不应再打扰用户(人已经在退出了),否则会误弹「登录已过期」。
try { if (sl<AppUserCubit>().state.user != null) {
sl<AuthCubit>().tokenExpired(); print(
} catch (ex) {} '>>> [DIO] 🚨🚨🚨 收到业务错误码 $code,触发 Token 过期处理!URL: ${response.requestOptions.uri},时间: ${DateTime.now()}',
);
try {
sl<AuthCubit>().tokenExpired();
} catch (ex) {}
}
} }
} }
return handler.next(response); return handler.next(response);
@@ -53,12 +58,15 @@ class DioClient {
onError: (DioException e, handler) async { onError: (DioException e, handler) async {
if (e.response?.statusCode == 401 || e.response?.statusCode == 403) { if (e.response?.statusCode == 401 || e.response?.statusCode == 403) {
print( // 🔥 同上:已退出登录(user==null)时不再触发过期弹窗
'>>> [DIO] 🚨🚨🚨 收到 HTTP ${e.response?.statusCode},触发 Token 过期处理!URL: ${e.requestOptions.uri},时间: ${DateTime.now()}', if (sl<AppUserCubit>().state.user != null) {
); print(
try { '>>> [DIO] 🚨🚨🚨 收到 HTTP ${e.response?.statusCode},触发 Token 过期处理!URL: ${e.requestOptions.uri},时间: ${DateTime.now()}',
sl<AuthCubit>().tokenExpired(); );
} catch (ex) {} try {
sl<AuthCubit>().tokenExpired();
} catch (ex) {}
}
} }
return handler.next(e); return handler.next(e);