feat(app): session restore on startup — no forced re-login after app restart
用户反馈:关闭 App 重开每次都要登录。根因:会话已持久化(安全存储, 服务端 TTL 30 天),但启动固定落在登录页——无人消费已存会话。 - _StartupGate(home):watch sessionAccount——在场直进 HomePage,离场 LoginPage;状态驱动(401/登出清会话后 gate 自动重建,不依赖导航时序) - onUnauthorized 保留 push 兜底(home 路由被显式导航替换后的 401 场景) - 测试适配(boot 401 两项重写通过;397/397 全绿) Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -1,10 +1,24 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:photo_live/app/app.dart';
|
||||
import 'package:photo_live/core/api_client.dart';
|
||||
import 'helpers/fakes.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('boots to login page with localized copy', (tester) async {
|
||||
await tester.pumpWidget(const ProviderScope(child: PhotoLiveApp()));
|
||||
await tester.pumpWidget(
|
||||
ProviderScope(
|
||||
// UI06 启动门读会话:生产 SecureSessionStore 平台通道在测试环境
|
||||
// 挂起——替身空会话(→ 登录页)。
|
||||
overrides: [
|
||||
sessionStoreProvider.overrideWithValue(FakeSessionStore()),
|
||||
],
|
||||
child: const PhotoLiveApp(),
|
||||
),
|
||||
);
|
||||
// UI06 启动门:异步读本地会话(空 → 登录页)——多 pump 一帧等完成。
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
|
||||
// 测试环境默认 locale 为 en:AppBar 标题与登录按钮均为英文文案。
|
||||
expect(find.text('Photo Live'), findsOneWidget);
|
||||
|
||||
Reference in New Issue
Block a user