diff --git a/app/lib/main.dart b/app/lib/main.dart index 71472cb..0350812 100644 --- a/app/lib/main.dart +++ b/app/lib/main.dart @@ -191,7 +191,7 @@ class _MyHomePageState extends State { mainAxisAlignment: MainAxisAlignment.center, children: [ TextButton( - onPressed: authentikApiState.start, + onPressed: () => authentikApiState.start(key), child: Text("Oauth2 Login"), ), Text('Current output:'), @@ -294,13 +294,15 @@ class _MyHomePageState extends State { case AuthentikUserSettingsChangeDialogStatus.userSettingsObtained: title = Text("User Settings Obtained"); children = [Text("You can now edit your user settings.")]; - for (var k in authentikApiState.allKeys) { - children.add(KeepOrDeleteKey(sshKey: k, isOurKey: k == key)); - } - if (!authentikApiState.allKeys.contains(key)) { - // If the key is not already in the list, add it - children.add(KeepOrDeleteKey(sshKey: key, isOurKey: true)); + children.add(KeepOrDeleteKey(sshKey: key, isOurKey: true)); + + for (var k in authentikApiState.allKeys) { + if (k == key) { + // Skip our key, since the widget is on top already + continue; + } + children.add(KeepOrDeleteKey(sshKey: k)); } actions.add( @@ -424,7 +426,7 @@ class AuthentikUserSettingsChangeDialogState extends ChangeNotifier { return await grant.handleAuthorizationResponse(queryParameters); } - Future start() async { + Future start(String currentKey) async { // Reset the state to be sure oauthClient = null; sessionCookie = null; @@ -468,6 +470,12 @@ class AuthentikUserSettingsChangeDialogState extends ChangeNotifier { .split('\n') .where((key) => key.isNotEmpty) .toList(); + + _keysToKeep = _allKeys.toList(); + if (!_keysToKeep.contains(currentKey)) { + // If the current key is not in the list of keys to keep, add it + _keysToKeep.add(currentKey); + } } else { throw Exception( "Expected 'attributes.sshPublicKeys' in user settings, but got: $userSettings",