Skip to content

Commit 6cd6dda

Browse files
authored
feat: rename onAuthStateChange to authStateChanges and add event key to posted notification (#163)
1 parent 44441b7 commit 6cd6dda

File tree

7 files changed

+22
-10
lines changed

7 files changed

+22
-10
lines changed

Examples/Examples.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,7 @@
527527
GCC_WARN_UNUSED_FUNCTION = YES;
528528
GCC_WARN_UNUSED_VARIABLE = YES;
529529
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
530+
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
530531
LD_RUNPATH_SEARCH_PATHS = (
531532
"$(inherited)",
532533
"@executable_path/Frameworks",
@@ -591,6 +592,7 @@
591592
GCC_WARN_UNUSED_FUNCTION = YES;
592593
GCC_WARN_UNUSED_VARIABLE = YES;
593594
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
595+
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
594596
LD_RUNPATH_SEARCH_PATHS = (
595597
"$(inherited)",
596598
"@executable_path/Frameworks",
@@ -672,7 +674,6 @@
672674
"INFOPLIST_KEY_UIStatusBarStyle[sdk=iphonesimulator*]" = UIStatusBarStyleDefault;
673675
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
674676
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
675-
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
676677
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
677678
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
678679
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
@@ -715,7 +716,6 @@
715716
"INFOPLIST_KEY_UIStatusBarStyle[sdk=iphonesimulator*]" = UIStatusBarStyleDefault;
716717
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
717718
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
718-
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
719719
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
720720
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
721721
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;

Examples/UserManagement/AppView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct AppView: View {
1919
}
2020
}
2121
.task {
22-
for await state in await supabase.auth.onAuthStateChange() {
22+
for await state in await supabase.auth.authStateChanges {
2323
if [.initialSession, .signedIn, .signedOut].contains(state.event) {
2424
isAuthenticated = state.session != nil
2525
}

Examples/UserManagement/ProfileView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ struct ProfileView: View {
8282
}
8383
}
8484
})
85-
.onChange(of: imageSelection) { _, newValue in
85+
.onChange(of: imageSelection) { newValue in
8686
guard let newValue else { return }
8787
loadTransferable(from: newValue)
8888
}

Sources/GoTrue/GoTrueClient.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public actor GoTrueClient {
173173
/// Listen for auth state changes.
174174
///
175175
/// An `.initialSession` is always emitted when this method is called.
176-
public func onAuthStateChange() async -> AsyncStream<(
176+
public var authStateChanges: AsyncStream<(
177177
event: AuthChangeEvent,
178178
session: Session?
179179
)> {
@@ -828,6 +828,14 @@ public actor GoTrueClient {
828828
extension GoTrueClient {
829829
/// Notification posted when an auth state event is triggered.
830830
public static let didChangeAuthStateNotification = Notification.Name(
831-
"DID_CHANGE_AUTH_STATE_NOTIFICATION"
831+
"GoTrueClient.didChangeAuthStateNotification"
832832
)
833+
834+
/// A user info key to retrieve the ``AuthChangeEvent`` value for a
835+
/// ``GoTrueClient/didChangeAuthStateNotification`` notification.
836+
public static let authChangeEventInfoKey = "GoTrueClient.authChangeEvent"
837+
838+
/// A user info key to retrieve the ``Session`` value for a
839+
/// ``GoTrueClient/didChangeAuthStateNotification`` notification.
840+
public static let authChangeSessionInfoKey = "GoTrueClient.authChangeSession"
833841
}

Sources/GoTrue/Internal/EventEmitter.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ extension EventEmitter {
4343
emit: { event, session, id in
4444
NotificationCenter.default.post(
4545
name: GoTrueClient.didChangeAuthStateNotification,
46-
object: nil
46+
object: nil,
47+
userInfo: [
48+
GoTrueClient.authChangeEventInfoKey: event,
49+
GoTrueClient.authChangeSessionInfoKey: session as Any,
50+
]
4751
)
4852
if let id {
4953
continuations.value[id]?.yield((event, session))

Sources/Supabase/SupabaseClient.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public final class SupabaseClient: @unchecked Sendable {
130130
private func listenForAuthEvents() {
131131
listenForAuthEventsTask.setValue(
132132
Task {
133-
for await (event, session) in await auth.onAuthStateChange() {
133+
for await (event, session) in await auth.authStateChanges {
134134
handleTokenChanged(event: event, session: session)
135135
}
136136
}

Tests/GoTrueTests/GoTrueClientTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import ConcurrencyExtras
1414
final class GoTrueClientTests: XCTestCase {
1515
fileprivate var api: APIClient!
1616

17-
func testOnAuthStateChange() async throws {
17+
func testAuthStateChanges() async throws {
1818
let session = Session.validSession
1919
let sut = makeSUT()
2020

@@ -25,7 +25,7 @@ final class GoTrueClientTests: XCTestCase {
2525
$0.eventEmitter = .live
2626
$0.sessionManager.session = { @Sendable _ in session }
2727
} operation: {
28-
let authStateStream = await sut.onAuthStateChange()
28+
let authStateStream = await sut.authStateChanges
2929

3030
let streamTask = Task {
3131
for await (event, _) in authStateStream {

0 commit comments

Comments
 (0)