Skip to content

Commit 2c53d42

Browse files
authored
feat(auth): Make the presentation anchor optional (#2545)
* feat(auth): Make the presentation anchor optional * Fix crash * added test * Revert "added test" This reverts commit 7684e0a. * Add test
1 parent b331b1d commit 2c53d42

File tree

27 files changed

+1445
-18
lines changed

27 files changed

+1445
-18
lines changed

Amplify/Categories/Auth/AuthCategory+ClientBehavior.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ extension AuthCategory: AuthCategoryBehavior {
3131

3232
#if canImport(AuthenticationServices)
3333
public func signInWithWebUI(
34-
presentationAnchor: AuthUIPresentationAnchor,
34+
presentationAnchor: AuthUIPresentationAnchor? = nil,
3535
options: AuthWebUISignInRequest.Options? = nil) async throws -> AuthSignInResult {
3636
return try await plugin.signInWithWebUI(presentationAnchor: presentationAnchor, options: options)
3737
}
3838

3939
public func signInWithWebUI(
4040
for authProvider: AuthProvider,
41-
presentationAnchor: AuthUIPresentationAnchor,
41+
presentationAnchor: AuthUIPresentationAnchor? = nil,
4242
options: AuthWebUISignInRequest.Options? = nil) async throws -> AuthSignInResult {
4343
return try await plugin.signInWithWebUI(for: authProvider,
4444
presentationAnchor: presentationAnchor,

Amplify/Categories/Auth/AuthCategoryBehavior.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public protocol AuthCategoryBehavior: AuthCategoryUserBehavior, AuthCategoryDevi
6868
/// - Parameters:
6969
/// - presentationAnchor: Anchor on which the UI is presented.
7070
/// - options: Parameters specific to plugin behavior.
71-
func signInWithWebUI(presentationAnchor: AuthUIPresentationAnchor,
71+
func signInWithWebUI(presentationAnchor: AuthUIPresentationAnchor?,
7272
options: AuthWebUISignInRequest.Options?) async throws -> AuthSignInResult
7373

7474
/// SignIn using an auth provider on a web UI
@@ -82,7 +82,7 @@ public protocol AuthCategoryBehavior: AuthCategoryUserBehavior, AuthCategoryDevi
8282
/// - presentationAnchor: Anchor on which the UI is presented.
8383
/// - options: Parameters specific to plugin behavior.
8484
func signInWithWebUI(for authProvider: AuthProvider,
85-
presentationAnchor: AuthUIPresentationAnchor,
85+
presentationAnchor: AuthUIPresentationAnchor?,
8686
options: AuthWebUISignInRequest.Options?) async throws -> AuthSignInResult
8787
#endif
8888

Amplify/Categories/Auth/Request/AuthWebUISignInRequest.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ import Foundation
1414
public struct AuthWebUISignInRequest: AmplifyOperationRequest {
1515

1616
/// Presentation anchor on which the webUI is displayed
17-
public let presentationAnchor: AuthUIPresentationAnchor
17+
public let presentationAnchor: AuthUIPresentationAnchor?
1818

1919
/// Optional auth provider to directly sign in with the provider
2020
public let authProvider: AuthProvider?
2121

2222
/// Extra request options defined in `AuthWebUISignInRequest.Options`
2323
public var options: Options
2424

25-
public init(presentationAnchor: AuthUIPresentationAnchor,
25+
public init(presentationAnchor: AuthUIPresentationAnchor?,
2626
authProvider: AuthProvider? = nil,
2727
options: Options) {
2828
self.presentationAnchor = presentationAnchor

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/HostedUI/InitializeHostedUISignIn.swift

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,14 @@ struct InitializeHostedUISignIn: Action {
2828
return
2929
}
3030

31-
guard let presentationAnchor = options.presentationAnchor else {
32-
fatalError("""
33-
Should not happen, initialize hostedUISignIn should always start with presentationanchor
34-
""")
35-
}
3631
await initializeHostedUI(
37-
presentationAnchor: presentationAnchor,
32+
presentationAnchor: options.presentationAnchor,
3833
environment: environment,
3934
hostedUIEnvironment: hostedUIEnvironment,
4035
dispatcher: dispatcher)
4136
}
4237

43-
func initializeHostedUI(presentationAnchor: AuthUIPresentationAnchor,
38+
func initializeHostedUI(presentationAnchor: AuthUIPresentationAnchor?,
4439
environment: AuthEnvironment,
4540
hostedUIEnvironment: HostedUIEnvironment,
4641
dispatcher: EventDispatcher) async {

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/ClientBehavior/AWSCognitoAuthPlugin+ClientBehavior.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import Foundation
99
import Amplify
10+
import AuthenticationServices
1011

1112
extension AWSCognitoAuthPlugin: AuthCategoryBehavior {
1213

@@ -47,7 +48,7 @@ extension AWSCognitoAuthPlugin: AuthCategoryBehavior {
4748
}
4849

4950
#if canImport(AuthenticationServices)
50-
public func signInWithWebUI(presentationAnchor: AuthUIPresentationAnchor,
51+
public func signInWithWebUI(presentationAnchor: AuthUIPresentationAnchor? = nil,
5152
options: AuthWebUISignInRequest.Options?) async throws -> AuthSignInResult {
5253
let options = options ?? AuthWebUISignInRequest.Options()
5354
let request = AuthWebUISignInRequest(presentationAnchor: presentationAnchor,
@@ -64,7 +65,7 @@ extension AWSCognitoAuthPlugin: AuthCategoryBehavior {
6465
}
6566

6667
public func signInWithWebUI(for authProvider: AuthProvider,
67-
presentationAnchor: AuthUIPresentationAnchor,
68+
presentationAnchor: AuthUIPresentationAnchor? = nil,
6869
options: AuthWebUISignInRequest.Options?) async throws -> AuthSignInResult {
6970
let options = options ?? AuthWebUISignInRequest.Options()
7071
let request = AuthWebUISignInRequest(presentationAnchor: presentationAnchor,

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/States/HostedUISignInState.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ struct HostedUISigningInState: Equatable {
3737

3838
let codeChallenge: String
3939

40-
let presentationAnchor: AuthUIPresentationAnchor
40+
let presentationAnchor: AuthUIPresentationAnchor?
4141

4242
let options: HostedUIOptions
4343
}

0 commit comments

Comments
 (0)