@@ -16,6 +16,7 @@ public actor AuthClient {
16
16
public var headers : [ String : String ]
17
17
public let flowType : AuthFlowType
18
18
public let localStorage : AuthLocalStorage
19
+ public let logger : SupabaseLogger ?
19
20
public let encoder : JSONEncoder
20
21
public let decoder : JSONDecoder
21
22
public let fetch : FetchHandler
@@ -27,6 +28,7 @@ public actor AuthClient {
27
28
/// - headers: Custom headers to be included in requests.
28
29
/// - flowType: The authentication flow type.
29
30
/// - localStorage: The storage mechanism for local data.
31
+ /// - logger: The logger to use.
30
32
/// - encoder: The JSON encoder to use for encoding requests.
31
33
/// - decoder: The JSON decoder to use for decoding responses.
32
34
/// - fetch: The asynchronous fetch handler for network requests.
@@ -35,6 +37,7 @@ public actor AuthClient {
35
37
headers: [ String : String ] = [ : ] ,
36
38
flowType: AuthFlowType = Configuration . defaultFlowType,
37
39
localStorage: AuthLocalStorage ,
40
+ logger: SupabaseLogger ? = nil ,
38
41
encoder: JSONEncoder = AuthClient . Configuration. jsonEncoder,
39
42
decoder: JSONDecoder = AuthClient . Configuration. jsonDecoder,
40
43
fetch: @escaping FetchHandler = { try await URLSession . shared. data ( for: $0) }
@@ -45,6 +48,7 @@ public actor AuthClient {
45
48
self . headers = headers
46
49
self . flowType = flowType
47
50
self . localStorage = localStorage
51
+ self . logger = logger
48
52
self . encoder = encoder
49
53
self . decoder = decoder
50
54
self . fetch = fetch
@@ -75,6 +79,10 @@ public actor AuthClient {
75
79
Dependencies . current. value!. currentDate
76
80
}
77
81
82
+ private var logger : SupabaseLogger ? {
83
+ Dependencies . current. value!. logger
84
+ }
85
+
78
86
/// Returns the session, refreshing it if necessary.
79
87
///
80
88
/// If no session can be found, a ``AuthError/sessionNotFound`` error is thrown.
@@ -94,6 +102,7 @@ public actor AuthClient {
94
102
/// - headers: Custom headers to be included in requests.
95
103
/// - flowType: The authentication flow type..
96
104
/// - localStorage: The storage mechanism for local data..
105
+ /// - logger: The logger to use.
97
106
/// - encoder: The JSON encoder to use for encoding requests.
98
107
/// - decoder: The JSON decoder to use for decoding responses.
99
108
/// - fetch: The asynchronous fetch handler for network requests.
@@ -102,6 +111,7 @@ public actor AuthClient {
102
111
headers: [ String : String ] = [ : ] ,
103
112
flowType: AuthFlowType = AuthClient . Configuration. defaultFlowType,
104
113
localStorage: AuthLocalStorage ,
114
+ logger: SupabaseLogger ? = nil ,
105
115
encoder: JSONEncoder = AuthClient . Configuration. jsonEncoder,
106
116
decoder: JSONDecoder = AuthClient . Configuration. jsonDecoder,
107
117
fetch: @escaping FetchHandler = { try await URLSession . shared. data ( for: $0) }
@@ -112,6 +122,7 @@ public actor AuthClient {
112
122
headers: headers,
113
123
flowType: flowType,
114
124
localStorage: localStorage,
125
+ logger: logger,
115
126
encoder: encoder,
116
127
decoder: decoder,
117
128
fetch: fetch
@@ -124,15 +135,19 @@ public actor AuthClient {
124
135
/// - Parameters:
125
136
/// - configuration: The client configuration.
126
137
public init ( configuration: Configuration ) {
127
- let api = APIClient . live ( http: HTTPClient ( fetchHandler: configuration. fetch) )
138
+ let api = APIClient . live ( http: HTTPClient (
139
+ logger: configuration. logger,
140
+ fetchHandler: configuration. fetch
141
+ ) )
128
142
129
143
self . init (
130
144
configuration: configuration,
131
145
sessionManager: . live,
132
146
codeVerifierStorage: . live,
133
147
api: api,
134
148
eventEmitter: . live,
135
- sessionStorage: . live
149
+ sessionStorage: . live,
150
+ logger: configuration. logger
136
151
)
137
152
}
138
153
@@ -143,7 +158,8 @@ public actor AuthClient {
143
158
codeVerifierStorage: CodeVerifierStorage ,
144
159
api: APIClient ,
145
160
eventEmitter: EventEmitter ,
146
- sessionStorage: SessionStorage
161
+ sessionStorage: SessionStorage ,
162
+ logger: SupabaseLogger ?
147
163
) {
148
164
mfa = AuthMFA ( )
149
165
@@ -159,7 +175,8 @@ public actor AuthClient {
159
175
try await self ? . refreshSession ( refreshToken: $0) ?? . empty
160
176
}
161
177
) ,
162
- codeVerifierStorage: codeVerifierStorage
178
+ codeVerifierStorage: codeVerifierStorage,
179
+ logger: logger
163
180
)
164
181
)
165
182
}
@@ -172,9 +189,11 @@ public actor AuthClient {
172
189
session: Session ?
173
190
) > {
174
191
let ( id, stream) = eventEmitter. attachListener ( )
192
+ logger? . debug ( " auth state change listener with id ' \( id. uuidString) ' attached. " )
175
193
176
194
Task { [ id] in
177
195
await emitInitialSession ( forStreamWithID: id)
196
+ logger? . debug ( " initial session for listener with id ' \( id. uuidString) ' emitted. " )
178
197
}
179
198
180
199
return stream
0 commit comments