Skip to content

[Auth] Add @discardableResult to avoid warnings #14486

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions FirebaseAuth/Sources/Swift/Auth/Auth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1613,6 +1613,25 @@ extension Auth: AuthInterop {
return authURLPresenter.canHandle(url: url)
}
}

/// Handles the given URL if it is recognized by `Auth`.
///
/// This method should be called when a URL is received by the scene delegate, ensuring that
/// authentication-related URLs are properly processed. It ensures that URLs passed from
/// `openURLContexts` are handled by the authentication system.
///
/// - Note: This method is available on iOS only.
///
/// - Parameter url: The URL received by the application delegate from any of the `openURL`
/// methods.
@objc open func handle(_ url: URL) throws {
guard canHandle(url) else {
throw AuthErrorUtils.error(
code: AuthErrorCode.internalError,
userInfo: [NSLocalizedDescriptionKey: "The URL can't be handled"]
)
}
}
#endif

/// The name of the `NSNotificationCenter` notification which is posted when the auth state
Expand Down
16 changes: 16 additions & 0 deletions FirebaseAuth/Tests/Unit/AuthTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2364,6 +2364,22 @@ class AuthTests: RPCBaseTests {
XCTAssertTrue(auth.application(UIApplication.shared, open: url, options: [:]))
XCTAssertTrue(fakeURLPresenter.canHandled)
}

func testAppHandleURL_AuthPresenterHandleURL() throws {
class FakeURLPresenter: AuthURLPresenter {
var canHandled = false
override func canHandle(url: URL) -> Bool {
canHandled = true
return true
}
}
let url = try XCTUnwrap(URL(string: "https://localhost"))
let fakeURLPresenter = FakeURLPresenter()
auth.authURLPresenter = fakeURLPresenter
XCTAssertFalse(fakeURLPresenter.canHandled)
try auth.handle(url)
XCTAssertTrue(fakeURLPresenter.canHandled)
}
#endif // os(iOS)

// MARK: Interoperability Tests
Expand Down
Loading