handle authentication failure in auth screen
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good

This commit is contained in:
2025-08-15 12:40:27 -05:00
parent 14998bf952
commit 224bf37e68
2 changed files with 43 additions and 21 deletions

View File

@@ -17,19 +17,37 @@ class Auth with ChangeNotifier {
bool get authenticated => _authenticated;
SecureKey get key => _key;
Future<void> authenticate(String user, String password) async {
final sodium = constants.sodium;
Future<bool> authenticate(String user, String password) async {
try {
final sodium = constants.sodium;
final keyHash = sodium.crypto.genericHash(
outLen: sodium.crypto.aeadXChaCha20Poly1305IETF.keyBytes,
message: Uint8List.fromList(password.toCharArray()),
);
final keyHash = sodium.crypto.genericHash(
outLen: sodium.crypto.aeadXChaCha20Poly1305IETF.keyBytes,
message: Uint8List.fromList(password.toCharArray()),
);
_authenticated = true;
_key = SecureKey.fromList(sodium, keyHash);
_user = user;
_key = SecureKey.fromList(sodium, keyHash);
_user = user;
notifyListeners();
final auth = await createAuth();
final response = await http.put(
Uri.parse(
Uri.encodeFull('${getBaseUri()}/api/v1/locations?auth=$auth'),
),
);
_authenticated = (response.statusCode == 200);
if (_authenticated) {
notifyListeners();
return _authenticated;
}
} catch (e) {
debugPrint('$e');
}
logoff();
return false;
}
Future<String> createAuth() async {

View File

@@ -57,22 +57,26 @@ class _AuthScreenState extends State<AuthScreen> {
}
setState(() => _enabled = false);
await auth.authenticate(
var authenticated = await auth.authenticate(
_userController.text.trim(),
_passwordController.text,
);
setState(() => _enabled = true);
// if (!mounted) return;
//
// if (!(ok == true || auth.authenticated)) {
// ScaffoldMessenger.of(context).showSnackBar(
// const SnackBar(
// content: Text('Invalid username or password'),
// behavior: SnackBarBehavior.floating,
// ),
// );
// }
if (authenticated) {
return;
}
if (!context.mounted) {
return;
}
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Invalid username or password'),
behavior: SnackBarBehavior.floating,
),
);
}
void navigateHomePostFrame() {