feat(app): смена сервера API и очистка данных устройства при выходе
Адрес бэкенда хранится в shared_preferences и читается до runApp; switchApiBaseUrl сбрасывает токены и кэш старого сервера. Выход стирает refresh-токен и sqlite-кэш ответов. Экран настроек переделан под разделы.
This commit is contained in:
+11
-7
@@ -38,7 +38,8 @@ class ResponseCacheDatabase extends _$ResponseCacheDatabase {
|
||||
|
||||
/// Replaces whatever was cached for [requestKey] — one row per endpoint+params,
|
||||
/// never a history.
|
||||
Future<void> put(String requestKey, Object? body) => into(cachedResponses).insertOnConflictUpdate(
|
||||
Future<void> put(String requestKey, Object? body) =>
|
||||
into(cachedResponses).insertOnConflictUpdate(
|
||||
CachedResponsesCompanion.insert(
|
||||
requestKey: requestKey,
|
||||
body: jsonEncode(body),
|
||||
@@ -46,6 +47,9 @@ class ResponseCacheDatabase extends _$ResponseCacheDatabase {
|
||||
),
|
||||
);
|
||||
|
||||
/// Drops every cached body — on sign-out, so the next account (or nobody) never sees them.
|
||||
Future<void> clear() => delete(cachedResponses).go();
|
||||
|
||||
/// The body last stored for [requestKey], or null if this endpoint+params was
|
||||
/// never fetched successfully on this device.
|
||||
Future<CacheEntry?> get(String requestKey) async {
|
||||
@@ -63,9 +67,9 @@ class ResponseCacheDatabase extends _$ResponseCacheDatabase {
|
||||
/// the compiled assets it loads there (regenerate with `just app-web-assets`
|
||||
/// whenever the `drift`/`sqlite3` package versions change).
|
||||
QueryExecutor _openConnection() => driftDatabase(
|
||||
name: 'response_cache',
|
||||
web: DriftWebOptions(
|
||||
sqlite3Wasm: Uri.parse('sqlite3.wasm'),
|
||||
driftWorker: Uri.parse('drift_worker.js'),
|
||||
),
|
||||
);
|
||||
name: 'response_cache',
|
||||
web: DriftWebOptions(
|
||||
sqlite3Wasm: Uri.parse('sqlite3.wasm'),
|
||||
driftWorker: Uri.parse('drift_worker.js'),
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user