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 {
// bare bones preflight for domain validity
if client.server.contains(".") && client.server.last != "." {
let instance: Instance = try await client.get(endpoint: Instances.instance) let instance: Instance = try await client.get(endpoint: Instances.instance)
withAnimation { withAnimation {
self.instance = instance self.instance = instance
} }
instanceFetchError = nil instanceFetchError = nil
} else {
instance = 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"