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
1 changed files with 10 additions and 4 deletions

View File

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