fix: improve transfer recognition and local data safety
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user