feat(app): смена сервера API и очистка данных устройства при выходе
Адрес бэкенда хранится в shared_preferences и читается до runApp; switchApiBaseUrl сбрасывает токены и кэш старого сервера. Выход стирает refresh-токен и sqlite-кэш ответов. Экран настроек переделан под разделы.
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../config.dart';
|
||||
import 'auth_controller.dart';
|
||||
|
||||
/// Points the app at [url] (null = the default). A different server means a different
|
||||
/// account, so the session ends first — while the clients still talk to the OLD server, so
|
||||
/// the refresh token is revoked there and never sent to the new one — and only then is the
|
||||
/// address changed. Takes a container rather than a `WidgetRef`: signing out replaces the
|
||||
/// calling screen, and a disposed widget's `ref` throws.
|
||||
Future<void> switchApiBaseUrl(ProviderContainer container, String? url) async {
|
||||
final next = url ?? defaultApiBaseUrl();
|
||||
if (next != container.read(apiBaseUrlProvider)) {
|
||||
await container.read(authControllerProvider.notifier).logout();
|
||||
}
|
||||
await container.read(apiBaseUrlProvider.notifier).save(url);
|
||||
}
|
||||
Reference in New Issue
Block a user