Skip to content

Commit dd3f525

Browse files
committed
Adds currentSession and currentUser function
1 parent ea25236 commit dd3f525

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

Sources/Auth/AuthClient.swift

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -886,12 +886,25 @@ public final class AuthClient: Sendable {
886886
)
887887
}
888888

889+
/// Returns the current session, if any.
890+
///
891+
/// The session returned by this property may be expired. Use ``session`` for a session that is guaranteed to be valid.
892+
public var currentSession: Session? {
893+
try? configuration.localStorage.getSession()?.session
894+
}
895+
896+
/// Returns the current user, if any.
897+
///
898+
/// The user returned by this property may be outdated. Use ``user(jwt:)`` method to get an up-to-date user instance.
899+
public var currentUser: User? {
900+
try? configuration.localStorage.getSession()?.session.user
901+
}
902+
889903
/// Gets the current user details if there is an existing session.
890904
/// - Parameter jwt: Takes in an optional access token jwt. If no jwt is provided, user() will
891905
/// attempt to get the jwt from the current session.
892906
///
893-
/// Should be used only when you require the most current user data. For faster results,
894-
/// session.user is recommended.
907+
/// Should be used only when you require the most current user data. For faster results, ``currentUser`` is recommended.
895908
public func user(jwt: String? = nil) async throws -> User {
896909
var request = HTTPRequest(url: configuration.url.appendingPathComponent("user"), method: .get)
897910

0 commit comments

Comments
 (0)