From 3ace5182bef5a4642ea3282750221ae95406eb09 Mon Sep 17 00:00:00 2001 From: Dariusz Rybicki <dariusz@elixxir.io> Date: Tue, 26 Jul 2022 13:03:26 +0100 Subject: [PATCH] Support ephemeral login in Login functor --- Sources/ElixxirDAppsSDK/Login.swift | 35 ++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/Sources/ElixxirDAppsSDK/Login.swift b/Sources/ElixxirDAppsSDK/Login.swift index e89fe54d..ec824892 100644 --- a/Sources/ElixxirDAppsSDK/Login.swift +++ b/Sources/ElixxirDAppsSDK/Login.swift @@ -2,33 +2,46 @@ import Bindings import XCTestDynamicOverlay public struct Login { - public var run: (Int, AuthCallbacks?, Data, Data) throws -> E2E + public var run: (Bool, Int, AuthCallbacks?, Data, Data) throws -> E2E public func callAsFunction( + ephemeral: Bool, cmixId: Int, authCallbacks: AuthCallbacks? = nil, identity: Data, e2eParamsJSON: Data ) throws -> E2E { - try run(cmixId, authCallbacks, identity, e2eParamsJSON) + try run(ephemeral, cmixId, authCallbacks, identity, e2eParamsJSON) } } extension Login { - public static let live = Login { cmixId, authCallbacks, identity, e2eParamsJSON in + public static let live = Login { ephemeral, cmixId, authCallbacks, identity, e2eParamsJSON in var error: NSError? - let bindingsE2E = BindingsLogin( - cmixId, - authCallbacks?.makeBindingsAuthCallbacks(), - identity, - e2eParamsJSON, - &error - ) + let bindingsE2E: BindingsE2e? + if ephemeral { + bindingsE2E = BindingsLogin( + cmixId, + authCallbacks?.makeBindingsAuthCallbacks(), + identity, + e2eParamsJSON, + &error + ) + } else { + bindingsE2E = BindingsLoginEphemeral( + cmixId, + authCallbacks?.makeBindingsAuthCallbacks(), + identity, + e2eParamsJSON, + &error + ) + } if let error = error { throw error } guard let bindingsE2E = bindingsE2E else { - fatalError("BindingsLogin returned `nil` without providing error") + let functionName = "BindingsLogin\(ephemeral ? "Ephemeral" : "")" + fatalError("\(functionName) returned `nil` without providing error") } return .live(bindingsE2E) } -- GitLab