Allow logging into homeservers without discovery working
This commit is contained in:
parent
724171384c
commit
620440e2a1
2 changed files with 38 additions and 20 deletions
|
|
@ -311,7 +311,7 @@ class ClientController extends AsyncNotifier<int> {
|
||||||
Future<Uri?> discoverHomeserver(Uri homeserver) async {
|
Future<Uri?> discoverHomeserver(Uri homeserver) async {
|
||||||
try {
|
try {
|
||||||
final response = await _sendCommand("discover_homeserver", {
|
final response = await _sendCommand("discover_homeserver", {
|
||||||
"user_id": "@fake-user:${homeserver.host}",
|
"user_id": "@fake-user:${homeserver.authority}",
|
||||||
});
|
});
|
||||||
return Uri.parse(response["m.homeserver"]?["base_url"]);
|
return Uri.parse(response["m.homeserver"]?["base_url"]);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,17 @@ class SelectServerPage extends HookConsumerWidget {
|
||||||
final homeserverUrl = useTextEditingController();
|
final homeserverUrl = useTextEditingController();
|
||||||
|
|
||||||
Future<void> setHomeserver(Uri? newHomeserver) async {
|
Future<void> setHomeserver(Uri? newHomeserver) async {
|
||||||
|
if (newHomeserver == null) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text(
|
||||||
|
"Failed to parse homeserver URL. Are you sure you typed it correctly?",
|
||||||
|
style: .new(color: theme.colorScheme.onErrorContainer),
|
||||||
|
),
|
||||||
|
backgroundColor: theme.colorScheme.errorContainer,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
isLoading.value = true;
|
isLoading.value = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
@ -33,26 +44,14 @@ class SelectServerPage extends HookConsumerWidget {
|
||||||
newHomeserver = Uri.https(newHomeserver!.path);
|
newHomeserver = Uri.https(newHomeserver!.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
final newUrl = newHomeserver == null
|
final newUrl = await ref
|
||||||
? null
|
|
||||||
: await ref
|
|
||||||
.read(ClientController.provider.notifier)
|
.read(ClientController.provider.notifier)
|
||||||
.discoverHomeserver(newHomeserver);
|
.discoverHomeserver(newHomeserver!);
|
||||||
|
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
if (newUrl == null) {
|
Future<void> tryLogin(Uri url) async {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
SnackBar(
|
|
||||||
content: Text(
|
|
||||||
"Homeserver verification failed. Is your homeserver down?",
|
|
||||||
style: .new(color: theme.colorScheme.onErrorContainer),
|
|
||||||
),
|
|
||||||
backgroundColor: theme.colorScheme.errorContainer,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
final codeResponse = await ref.watch(
|
final codeResponse = await ref.watch(
|
||||||
AuthUrlController.provider(newUrl).future,
|
AuthUrlController.provider(url).future,
|
||||||
);
|
);
|
||||||
|
|
||||||
await ref.watch(LaunchHelper.provider).launchUrl(codeResponse.url);
|
await ref.watch(LaunchHelper.provider).launchUrl(codeResponse.url);
|
||||||
|
|
@ -70,7 +69,7 @@ class SelectServerPage extends HookConsumerWidget {
|
||||||
.watch(ClientController.provider.notifier)
|
.watch(ClientController.provider.notifier)
|
||||||
.exchangeToken(
|
.exchangeToken(
|
||||||
.new(
|
.new(
|
||||||
homeserverUrl: newUrl,
|
homeserverUrl: url,
|
||||||
codeVerifier: codeResponse.codeVerifier,
|
codeVerifier: codeResponse.codeVerifier,
|
||||||
redirectUri: .new(
|
redirectUri: .new(
|
||||||
scheme: "nexus.federated.nexus",
|
scheme: "nexus.federated.nexus",
|
||||||
|
|
@ -78,7 +77,7 @@ class SelectServerPage extends HookConsumerWidget {
|
||||||
),
|
),
|
||||||
code: code,
|
code: code,
|
||||||
clientId: await ref.watch(
|
clientId: await ref.watch(
|
||||||
ClientIdController.provider(newUrl).future,
|
ClientIdController.provider(url).future,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
@ -89,6 +88,25 @@ class SelectServerPage extends HookConsumerWidget {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (newUrl == null) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text(
|
||||||
|
"Homeserver verification failed.",
|
||||||
|
style: .new(color: theme.colorScheme.onErrorContainer),
|
||||||
|
),
|
||||||
|
action: SnackBarAction(
|
||||||
|
onPressed: () => tryLogin(newHomeserver!),
|
||||||
|
label: "Attempt log in anyways",
|
||||||
|
textColor: theme.colorScheme.onErrorContainer,
|
||||||
|
),
|
||||||
|
backgroundColor: theme.colorScheme.errorContainer,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
tryLogin(newUrl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (error, stackTrace) {
|
} catch (error, stackTrace) {
|
||||||
showError(error, stackTrace);
|
showError(error, stackTrace);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue