File tree Expand file tree Collapse file tree 2 files changed +19
-8
lines changed Expand file tree Collapse file tree 2 files changed +19
-8
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,16 @@ public final class AuthClient: Sendable {
27
27
}
28
28
}
29
29
30
+ /// Returns the session.
31
+ ///
32
+ /// - Parameters:
33
+ /// - shouldValidateExpiration: If the session should be refresh, if necessary.
34
+ ///
35
+ /// If no session can be found, a ``AuthError/sessionNotFound`` error is thrown.
36
+ public func session( shouldValidateExpiration: Bool = true ) async throws -> Session {
37
+ try await sessionManager. session ( shouldValidateExpiration: shouldValidateExpiration)
38
+ }
39
+
30
40
/// Namespace for accessing multi-factor authentication API.
31
41
public let mfa = AuthMFA ( )
32
42
/// Namespace for the GoTrue admin methods.
Original file line number Diff line number Diff line change @@ -17,21 +17,22 @@ actor SessionManager {
17
17
}
18
18
19
19
func session( shouldValidateExpiration: Bool = true ) async throws -> Session {
20
+ guard let currentSession = try storage. getSession ( ) else {
21
+ throw AuthError . sessionNotFound
22
+ }
23
+
24
+
25
+ if currentSession. isValid || !shouldValidateExpiration {
26
+ return currentSession. session
27
+ }
28
+
20
29
if let task {
21
30
return try await task. value
22
31
}
23
32
24
33
task = Task {
25
34
defer { task = nil }
26
35
27
- guard let currentSession = try storage. getSession ( ) else {
28
- throw AuthError . sessionNotFound
29
- }
30
-
31
- if currentSession. isValid || !shouldValidateExpiration {
32
- return currentSession. session
33
- }
34
-
35
36
let session = try await sessionRefresher. refreshSession ( currentSession. session. refreshToken)
36
37
try update ( session)
37
38
return session
You can’t perform that action at this time.
0 commit comments