refactor
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good

This commit is contained in:
Scott E. Graves 2025-03-24 19:18:52 -05:00
parent aa23decaff
commit efcb15e2e3
5 changed files with 12 additions and 12 deletions

View File

@ -3,7 +3,8 @@ import 'package:collection/collection.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:repertory/constants.dart' as constants;
import 'package:sodium_libs/sodium_libs.dart';
import 'package:repertory/models/auth.dart';
import 'package:sodium_libs/sodium_libs.dart' show SecureKey, StringX;
typedef Validator = bool Function(String);
@ -106,8 +107,8 @@ Map<String, dynamic> createDefaultSettings(String mountType) {
return {};
}
void displayAuthError() {
if (constants.navigatorKey.currentContext == null) {
void displayAuthError(Auth auth) {
if (!auth.authenticated || constants.navigatorKey.currentContext == null) {
return;
}

View File

@ -54,9 +54,11 @@ class Auth with ChangeNotifier {
void logoff() {
_authenticated = false;
_key = SecureKey.random(constants.sodium, 32);
_user = "";
mountList?.clear();
notifyListeners();
mountList?.clear();
}
}

View File

@ -207,7 +207,7 @@ class Mount with ChangeNotifier {
);
if (response.statusCode == 401) {
displayAuthError();
displayAuthError(_auth);
_auth.logoff();
return false;
}

View File

@ -63,7 +63,7 @@ class MountList with ChangeNotifier {
);
if (response.statusCode == 401) {
displayAuthError();
displayAuthError(_auth);
_auth.logoff();
return;
}
@ -155,7 +155,7 @@ class MountList with ChangeNotifier {
ret = true;
break;
case 401:
displayAuthError();
displayAuthError(_auth);
_auth.logoff();
break;
case 404:

View File

@ -106,7 +106,6 @@ class _UISettingsWidgetState extends State<UISettingsWidget> {
void dispose() {
final settings = getChanged(widget.origSettings, widget.settings);
if (settings.isNotEmpty) {
debugPrint("start");
final key =
Provider.of<Auth>(
constants.navigatorKey.currentContext!,
@ -114,15 +113,13 @@ class _UISettingsWidgetState extends State<UISettingsWidget> {
).key;
convertAllToString(settings, key)
.then((map) async {
debugPrint("map");
try {
final authProvider = Provider.of<Auth>(
constants.navigatorKey.currentContext!,
listen: false,
);
final auth = await authProvider.createAuth();
debugPrint("auth");
final auth = await authProvider.createAuth();
final response = await http.put(
Uri.parse(
Uri.encodeFull(
@ -132,7 +129,7 @@ class _UISettingsWidgetState extends State<UISettingsWidget> {
);
if (response.statusCode == 401) {
displayAuthError();
displayAuthError(authProvider);
authProvider.logoff();
}
} catch (e) {