Restore the WFClient when the WriteFreely model initializes

This commit is contained in:
Angelo Stavrow 2020-08-31 11:24:38 -04:00
parent 07d306a196
commit 45b6fb533c
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE

View File

@ -26,6 +26,22 @@ class WriteFreelyModel: ObservableObject {
DispatchQueue.main.async {
self.account.restoreState()
if self.account.isLoggedIn {
guard let serverURL = URL(string: self.account.server) else {
print("Server URL not found")
return
}
guard let token = self.fetchTokenFromKeychain(
username: self.account.username,
server: self.account.server
) else {
print("Could not fetch token from Keychain")
return
}
self.account.login(WFUser(token: token, username: self.account.username))
self.client = WFClient(for: serverURL)
self.client?.user = self.account.user
}
}
}
}