fix: improve transfer recognition and local data safety

This commit is contained in:
2026-07-26 21:36:46 +08:00
parent 7df25edd96
commit 882293343e
21 changed files with 505 additions and 128 deletions
+23 -6
View File
@@ -53,10 +53,20 @@ class UserProfile {
}) : aiCompanion = null;
}
class AuthLoginResult {
final bool accountClosureCancelled;
final UserProfile profile;
const AuthLoginResult({
required this.accountClosureCancelled,
required this.profile,
});
}
class AuthApi {
static final _dio = ApiClient.instance.dio;
static Future<void> register(
static Future<UserProfile> register(
String username,
String password, {
required bool agreedToTerms,
@@ -70,21 +80,28 @@ class AuthApi {
},
);
await ApiClient.instance.saveToken(response.data['token'] as String);
await me();
return me(forceRemote: true);
}
static Future<bool> login(String username, String password) async {
static Future<AuthLoginResult> login(String username, String password) async {
final response = await _dio.post(
'/api/auth/login',
data: {'username': username, 'password': password},
);
await ApiClient.instance.saveToken(response.data['token'] as String);
return response.data['accountClosureCancelled'] as bool? ?? false;
final profile = await me(forceRemote: true);
return AuthLoginResult(
accountClosureCancelled:
response.data['accountClosureCancelled'] as bool? ?? false,
profile: profile,
);
}
static Future<UserProfile> me() async {
static Future<UserProfile> me({bool forceRemote = false}) async {
final session = SessionStore.instance;
if (session.isGuest || (session.isAccount && session.shouldUseLocalOnly)) {
if (!forceRemote &&
(session.isGuest ||
(session.isAccount && session.shouldUseLocalOnly))) {
return _localProfile();
}
try {