ComposableAuthorizationProvider is a composable component built with the Swift Composable Architecture for handling Sign in with Apple on iOS, macOS, tvOS.
ComposableAuthorizationProvider is available via Swift Package Manager
ComposableAuthorizationProvider
gives you access to a new provider called AuthorizationProvider
. It can be integrated within your composable app like this :
public struct SomeEnvironment {
public var authorizationProvider: AuthorizationProvider
public init(
authorizationProvider: AuthorizationProvider = .live
) {
self.authorizationProvider = authorizationProvider
}
}
public enum SomeAction: Equatable {
case someAction
case someSignInAction
case authorizationProvider(AuthorizationControllerClient.DelegateEvent)
}
public let reducer = Reducer<SomeState, SomeAction, SomeEnvironment>.combine(
Reducer { state, action, environment in
switch action {
case .someAction:
return environment.authorizationProvider.getCredentialState("someUserId").eraseToEffect().map { state in
// TODO: Decide when you want to perform credential challenges
// Make a credential challenge
environment.authorizationProvider.authorizationController.performRequest(.default).map(SomeAction.authorizationProvider)
}
case .someSignInAction:
// Make a credential challenge
return environment.authorizationProvider.authorizationController.performRequest(.default).map(SomeAction.authorizationProvider)
}
},
...
)
public var body: some View {
ZStack{
Color.accentColor.edgesIgnoringSafeArea(.all)
VStack {
Spacer()
if viewStore.loginButtonVisible {
SignInWithAppleButton(type: .default, style: .white)
.frame(width: UIScreen.main.bounds.width / 2, height: 30)
.onTapGesture {
self.viewStore.send(.someSignInAction)
}
}
}
}
}
ComposableAuthorizationProvider is available under the MIT license. See the LICENSE file for more info.
link |
Stars: 2 |
Last commit: 2 weeks ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics