-
Notifications
You must be signed in to change notification settings - Fork 0
fix: add authentication callback #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,28 +5,38 @@ public struct RxSignInView<Header: View>: View { | |
| @Bindable private var manager: OAuthManager | ||
| private let appearance: RxSignInAppearance | ||
| private let customHeader: Header? | ||
| private let onAuthSuccess: (() -> Void)? | ||
| private let onAuthFailed: ((Error) -> Void)? | ||
|
|
||
| // MARK: - Simple Init (appearance struct) | ||
|
|
||
| public init( | ||
| manager: OAuthManager, | ||
| appearance: RxSignInAppearance = RxSignInAppearance() | ||
| appearance: RxSignInAppearance = RxSignInAppearance(), | ||
| onAuthSuccess: (() -> Void)? = nil, | ||
| onAuthFailed: ((Error) -> Void)? = nil | ||
| ) where Header == Never { | ||
| self.manager = manager | ||
| self.appearance = appearance | ||
| self.customHeader = nil | ||
| self.onAuthSuccess = onAuthSuccess | ||
| self.onAuthFailed = onAuthFailed | ||
| } | ||
|
|
||
| // MARK: - Advanced Init (ViewBuilder for custom header) | ||
|
|
||
| public init( | ||
| manager: OAuthManager, | ||
| appearance: RxSignInAppearance = RxSignInAppearance(), | ||
| onAuthSuccess: (() -> Void)? = nil, | ||
| onAuthFailed: ((Error) -> Void)? = nil, | ||
| @ViewBuilder header: () -> Header | ||
|
Comment on lines
28
to
33
|
||
| ) { | ||
| self.manager = manager | ||
| self.appearance = appearance | ||
| self.customHeader = header() | ||
| self.onAuthSuccess = onAuthSuccess | ||
| self.onAuthFailed = onAuthFailed | ||
| } | ||
|
|
||
| public var body: some View { | ||
|
|
@@ -65,8 +75,9 @@ public struct RxSignInView<Header: View>: View { | |
| Task { | ||
| do { | ||
| try await manager.authenticate() | ||
| onAuthSuccess?() | ||
| } catch { | ||
| // Error is handled by the manager | ||
| onAuthFailed?(error) | ||
| } | ||
|
Comment on lines
75
to
81
|
||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onAuthSuccess/onAuthFailedare stored on the view, so the corresponding initializer parameters need to be@escaping(otherwise this won’t compile under Swift’s non-escaping default). Given Swift 6 strict concurrency, also consider annotating these callback types as@MainActor/@Sendableso they can be safely captured from theTaskused by the button action.