diff --git a/HostApp/HostApp/Views/StartSessionView.swift b/HostApp/HostApp/Views/StartSessionView.swift index cac29e36..42f64401 100644 --- a/HostApp/HostApp/Views/StartSessionView.swift +++ b/HostApp/HostApp/Views/StartSessionView.swift @@ -13,6 +13,7 @@ struct StartSessionView: View { @ObservedObject var viewModel = StartSessionViewModel() @Binding var sessionID: String @Binding var isPresentingContainerView: Bool + @State private var showAlert = false var body: some View { VStack { @@ -31,18 +32,34 @@ struct StartSessionView: View { dark: .hex("#7dd6e8") ), action: { - viewModel.createSession { - sessionID = $0 - isPresentingContainerView = true + viewModel.createSession { sessionId, err in + if let sessionId = sessionId { + sessionID = sessionId + isPresentingContainerView = true + } + + showAlert = err != nil } }, enabled: viewModel.isSignedIn ) + .alert(isPresented: $showAlert) { + Alert( + title: Text("Error Creating Liveness Session"), + message: Text("Unable to create a liveness session id. Please try again."), + dismissButton: .default( + Text("OK"), + action: { + isPresentingContainerView = false + } + ) + ) + } Spacer() HStack { Spacer() - Text("v0.1.16") + Text("v0.1.19") .font(.callout) .padding() } diff --git a/HostApp/HostApp/Views/StartSessionViewModel.swift b/HostApp/HostApp/Views/StartSessionViewModel.swift index a009fc01..8b8484db 100644 --- a/HostApp/HostApp/Views/StartSessionViewModel.swift +++ b/HostApp/HostApp/Views/StartSessionViewModel.swift @@ -25,14 +25,16 @@ class StartSessionViewModel: ObservableObject { ? .signedIn(action: signOut) : .signedOut(action: signIn) } catch { + presentationState = .signedOut(action: signIn) print("Error fetching auth session", error) } } } - func createSession(_ completion: @escaping (String) -> Void) { + func createSession(_ completion: @escaping (String?, Error?) -> Void) { Task { @MainActor in + let currentPresentationState = presentationState presentationState = .loading let request = RESTRequest( apiName: "liveness", @@ -45,9 +47,12 @@ class StartSessionViewModel: ObservableObject { CreateSessionResponse.self, from: data ) - completion(response.sessionId) + presentationState = currentPresentationState + completion(response.sessionId, nil) } catch { + presentationState = currentPresentationState print("Error creating session", error) + completion(nil, error) } } }