Адрес бэкенда хранится в shared_preferences и читается до runApp; switchApiBaseUrl сбрасывает токены и кэш старого сервера. Выход стирает refresh-токен и sqlite-кэш ответов. Экран настроек переделан под разделы.
18 lines
851 B
Dart
18 lines
851 B
Dart
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);
|
|
}
|