Primitive validation of domain before trying to connect (#287)

* Primitive validation of domain before trying to connect

Every domain needs at least one "dot" and can't end with a "dot." Don't try connecting unless/until these are both true.

* Correctly reset instance when invalid

Co-authored-by: Thomas Ricouard <ricouard77@gmail.com>
This commit is contained in:
Steve Kalkwarf 2023-01-23 00:41:01 -05:00 committed by GitHub
parent fe1d886b62
commit 3658c4f829
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -87,11 +87,17 @@ struct AddAccountView: View {
let client = Client(server: newValue) let client = Client(server: newValue)
Task { Task {
do { do {
let instance: Instance = try await client.get(endpoint: Instances.instance) // bare bones preflight for domain validity
withAnimation { if client.server.contains(".") && client.server.last != "." {
self.instance = instance let instance: Instance = try await client.get(endpoint: Instances.instance)
withAnimation {
self.instance = instance
}
instanceFetchError = nil
} else {
instance = nil
instanceFetchError = nil
} }
instanceFetchError = nil
} catch _ as DecodingError { } catch _ as DecodingError {
instance = nil instance = nil
instanceFetchError = "account.add.error.instance-not-supported" instanceFetchError = "account.add.error.instance-not-supported"