parent
d47c4ae15c
commit
df592b3f38
3 changed files with 35 additions and 4 deletions
|
|
@ -15,6 +15,7 @@ import "package:nexus/models/event.dart";
|
||||||
import "package:nexus/models/event_context.dart";
|
import "package:nexus/models/event_context.dart";
|
||||||
import "package:nexus/models/mentions_response.dart";
|
import "package:nexus/models/mentions_response.dart";
|
||||||
import "package:nexus/models/gomuks_config.dart";
|
import "package:nexus/models/gomuks_config.dart";
|
||||||
|
import "package:nexus/models/gomuks_exception.dart";
|
||||||
import "package:nexus/models/oauth_auth_code_response.dart";
|
import "package:nexus/models/oauth_auth_code_response.dart";
|
||||||
import "package:nexus/models/open_graph_data.dart";
|
import "package:nexus/models/open_graph_data.dart";
|
||||||
import "package:nexus/models/paginate.dart";
|
import "package:nexus/models/paginate.dart";
|
||||||
|
|
@ -112,7 +113,7 @@ class ClientController extends AsyncNotifier<int> {
|
||||||
final json = response.buf.toJsonAndFree();
|
final json = response.buf.toJsonAndFree();
|
||||||
|
|
||||||
if (response.command.cast<Utf8>().toDartString() == "error") {
|
if (response.command.cast<Utf8>().toDartString() == "error") {
|
||||||
throw json;
|
throw GomuksException(json.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
return json;
|
return json;
|
||||||
|
|
|
||||||
11
lib/models/gomuks_exception.dart
Normal file
11
lib/models/gomuks_exception.dart
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
class GomuksException implements Exception {
|
||||||
|
final String message;
|
||||||
|
const GomuksException(this.message);
|
||||||
|
|
||||||
|
/// The Matrix error code, if gomuks returned an error in the form `M_CODE (HTTP 404): message`
|
||||||
|
String? get errorCode =>
|
||||||
|
RegExp(r"^(M_[A-Z_]+)").firstMatch(message)?.group(1);
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() => message;
|
||||||
|
}
|
||||||
|
|
@ -8,7 +8,9 @@ import "package:nexus/controllers/client.dart";
|
||||||
import "package:nexus/controllers/client_id.dart";
|
import "package:nexus/controllers/client_id.dart";
|
||||||
import "package:nexus/helpers/launch_helper.dart";
|
import "package:nexus/helpers/launch_helper.dart";
|
||||||
import "package:nexus/main.dart";
|
import "package:nexus/main.dart";
|
||||||
|
import "package:nexus/models/gomuks_exception.dart";
|
||||||
import "package:nexus/models/homeserver.dart";
|
import "package:nexus/models/homeserver.dart";
|
||||||
|
import "package:nexus/models/oauth_auth_code_response.dart";
|
||||||
import "package:nexus/widgets/pages/settings.dart";
|
import "package:nexus/widgets/pages/settings.dart";
|
||||||
import "package:nexus/widgets/appbar.dart";
|
import "package:nexus/widgets/appbar.dart";
|
||||||
import "package:nexus/widgets/divider_text.dart";
|
import "package:nexus/widgets/divider_text.dart";
|
||||||
|
|
@ -48,9 +50,26 @@ class const SelectServerPage({super.key}) extends HookConsumerWidget {
|
||||||
|
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
Future<void> tryLogin(Uri url) async {
|
Future<void> tryLogin(Uri url) async {
|
||||||
final codeResponse = await ref.watch(
|
final OAuthAuthCodeResponse codeResponse;
|
||||||
|
try {
|
||||||
|
codeResponse = await ref.watch(
|
||||||
AuthUrlController.provider(url).future,
|
AuthUrlController.provider(url).future,
|
||||||
);
|
);
|
||||||
|
} on GomuksException catch (error) {
|
||||||
|
if (error.errorCode != "M_UNRECOGNIZED") rethrow;
|
||||||
|
if (context.mounted) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text(
|
||||||
|
"${url.host} doesn't support OAuth login, which Nexus requires. Try a different homeserver, or ask your homeserver's admin to enable OAuth.",
|
||||||
|
style: .new(color: theme.colorScheme.onErrorContainer),
|
||||||
|
),
|
||||||
|
backgroundColor: theme.colorScheme.errorContainer,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
await ref.read(LaunchHelper.provider).launchUrl(codeResponse.url);
|
await ref.read(LaunchHelper.provider).launchUrl(codeResponse.url);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue