diff --git a/Examples/Examples.xcodeproj/project.pbxproj b/Examples/Examples.xcodeproj/project.pbxproj index 414035f5..cd986255 100644 --- a/Examples/Examples.xcodeproj/project.pbxproj +++ b/Examples/Examples.xcodeproj/project.pbxproj @@ -527,6 +527,7 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; INFOPLIST_KEY_UILaunchScreen_Generation = YES; + IPHONEOS_DEPLOYMENT_TARGET = 16.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -591,6 +592,7 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; INFOPLIST_KEY_UILaunchScreen_Generation = YES; + IPHONEOS_DEPLOYMENT_TARGET = 16.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -672,7 +674,6 @@ "INFOPLIST_KEY_UIStatusBarStyle[sdk=iphonesimulator*]" = UIStatusBarStyleDefault; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; - IPHONEOS_DEPLOYMENT_TARGET = 17.0; LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks"; "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks"; LOCALIZATION_PREFERS_STRING_CATALOGS = YES; @@ -715,7 +716,6 @@ "INFOPLIST_KEY_UIStatusBarStyle[sdk=iphonesimulator*]" = UIStatusBarStyleDefault; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; - IPHONEOS_DEPLOYMENT_TARGET = 17.0; LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks"; "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks"; LOCALIZATION_PREFERS_STRING_CATALOGS = YES; diff --git a/Examples/UserManagement/AppView.swift b/Examples/UserManagement/AppView.swift index 1cfc1757..35aa8a8e 100644 --- a/Examples/UserManagement/AppView.swift +++ b/Examples/UserManagement/AppView.swift @@ -19,7 +19,7 @@ struct AppView: View { } } .task { - for await state in await supabase.auth.onAuthStateChange() { + for await state in await supabase.auth.authStateChanges { if [.initialSession, .signedIn, .signedOut].contains(state.event) { isAuthenticated = state.session != nil } diff --git a/Examples/UserManagement/ProfileView.swift b/Examples/UserManagement/ProfileView.swift index 404958f3..e5c9f152 100644 --- a/Examples/UserManagement/ProfileView.swift +++ b/Examples/UserManagement/ProfileView.swift @@ -82,7 +82,7 @@ struct ProfileView: View { } } }) - .onChange(of: imageSelection) { _, newValue in + .onChange(of: imageSelection) { newValue in guard let newValue else { return } loadTransferable(from: newValue) } diff --git a/Sources/GoTrue/GoTrueClient.swift b/Sources/GoTrue/GoTrueClient.swift index 72feb016..23b48e87 100644 --- a/Sources/GoTrue/GoTrueClient.swift +++ b/Sources/GoTrue/GoTrueClient.swift @@ -173,7 +173,7 @@ public actor GoTrueClient { /// Listen for auth state changes. /// /// An `.initialSession` is always emitted when this method is called. - public func onAuthStateChange() async -> AsyncStream<( + public var authStateChanges: AsyncStream<( event: AuthChangeEvent, session: Session? )> { @@ -828,6 +828,14 @@ public actor GoTrueClient { extension GoTrueClient { /// Notification posted when an auth state event is triggered. public static let didChangeAuthStateNotification = Notification.Name( - "DID_CHANGE_AUTH_STATE_NOTIFICATION" + "GoTrueClient.didChangeAuthStateNotification" ) + + /// A user info key to retrieve the ``AuthChangeEvent`` value for a + /// ``GoTrueClient/didChangeAuthStateNotification`` notification. + public static let authChangeEventInfoKey = "GoTrueClient.authChangeEvent" + + /// A user info key to retrieve the ``Session`` value for a + /// ``GoTrueClient/didChangeAuthStateNotification`` notification. + public static let authChangeSessionInfoKey = "GoTrueClient.authChangeSession" } diff --git a/Sources/GoTrue/Internal/EventEmitter.swift b/Sources/GoTrue/Internal/EventEmitter.swift index bea9d946..38cc610c 100644 --- a/Sources/GoTrue/Internal/EventEmitter.swift +++ b/Sources/GoTrue/Internal/EventEmitter.swift @@ -43,7 +43,11 @@ extension EventEmitter { emit: { event, session, id in NotificationCenter.default.post( name: GoTrueClient.didChangeAuthStateNotification, - object: nil + object: nil, + userInfo: [ + GoTrueClient.authChangeEventInfoKey: event, + GoTrueClient.authChangeSessionInfoKey: session as Any, + ] ) if let id { continuations.value[id]?.yield((event, session)) diff --git a/Sources/Supabase/SupabaseClient.swift b/Sources/Supabase/SupabaseClient.swift index 03edbe34..3e48c530 100644 --- a/Sources/Supabase/SupabaseClient.swift +++ b/Sources/Supabase/SupabaseClient.swift @@ -130,7 +130,7 @@ public final class SupabaseClient: @unchecked Sendable { private func listenForAuthEvents() { listenForAuthEventsTask.setValue( Task { - for await (event, session) in await auth.onAuthStateChange() { + for await (event, session) in await auth.authStateChanges { handleTokenChanged(event: event, session: session) } } diff --git a/Tests/GoTrueTests/GoTrueClientTests.swift b/Tests/GoTrueTests/GoTrueClientTests.swift index c3fc300f..1722ccb6 100644 --- a/Tests/GoTrueTests/GoTrueClientTests.swift +++ b/Tests/GoTrueTests/GoTrueClientTests.swift @@ -14,7 +14,7 @@ import ConcurrencyExtras final class GoTrueClientTests: XCTestCase { fileprivate var api: APIClient! - func testOnAuthStateChange() async throws { + func testAuthStateChanges() async throws { let session = Session.validSession let sut = makeSUT() @@ -25,7 +25,7 @@ final class GoTrueClientTests: XCTestCase { $0.eventEmitter = .live $0.sessionManager.session = { @Sendable _ in session } } operation: { - let authStateStream = await sut.onAuthStateChange() + let authStateStream = await sut.authStateChanges let streamTask = Task { for await (event, _) in authStateStream {