Skip to content

Export ability to get session without validation #373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions Sources/Auth/AuthClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -886,12 +886,25 @@ public final class AuthClient: Sendable {
)
}

/// Returns the current session, if any.
///
/// The session returned by this property may be expired. Use ``session`` for a session that is guaranteed to be valid.
public var currentSession: Session? {
try? configuration.localStorage.getSession()?.session
}

/// Returns the current user, if any.
///
/// The user returned by this property may be outdated. Use ``user(jwt:)`` method to get an up-to-date user instance.
public var currentUser: User? {
try? configuration.localStorage.getSession()?.session.user
}

/// Gets the current user details if there is an existing session.
/// - Parameter jwt: Takes in an optional access token jwt. If no jwt is provided, user() will
/// attempt to get the jwt from the current session.
///
/// Should be used only when you require the most current user data. For faster results,
/// session.user is recommended.
/// Should be used only when you require the most current user data. For faster results, ``currentUser`` is recommended.
public func user(jwt: String? = nil) async throws -> User {
var request = HTTPRequest(url: configuration.url.appendingPathComponent("user"), method: .get)

Expand Down