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

View File

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

View File

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

View File

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

View File

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