User

public extension User
extension User: ObservableObject
  • Links the currently authenticated user with a new identity, where the identity is defined by the credential specified as a parameter. This will only be successful if this User is the currently authenticated with the client from which it was created. On success a new user will be returned with the new linked credentials. @param credentials The Credentials used to link the user to a new identity. @completion A completion that eventually return Result.success(User) with user’s data or Result.failure(Error).

    Declaration

    Swift

    @preconcurrency
    func linkUser(credentials: Credentials, _ completion: @escaping @Sendable (Result<User, Error>) -> Void)
  • Links the currently authenticated user with a new identity, where the identity is defined by the credential specified as a parameter. This will only be successful if this User is the currently authenticated with the client from which it was created. On success a new user will be returned with the new linked credentials. @param credentials The Credentials used to link the user to a new identity. @returns A publisher that eventually return Result.success or Error.

    Declaration

    Swift

    @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
    func linkUser(credentials: Credentials) -> Future<User, Error>
  • linkUser(credentials:) Asynchronous

    Links the currently authenticated user with a new identity, where the identity is defined by the credential specified as a parameter. This will only be successful if this User is the currently authenticated with the client from which it was created. On success a new user will be returned with the new linked credentials.

    Declaration

    Swift

    @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
    func linkUser(credentials: Credentials) async throws -> User

    Parameters

    credentials

    The Credentials used to link the user to a new identity.

    Return Value

    A User after successfully update its identity.

  • Create a sync configuration instance.

    Declaration

    Swift

    @preconcurrency
    func configuration<T: BSON>(partitionValue: T,
                                clientResetMode: ClientResetMode = .recoverUnsyncedChanges(beforeReset: nil, afterReset: nil),
                                cancelAsyncOpenOnNonFatalErrors: Bool = false) -> Realm.Configuration

    Parameters

    partitionValue

    The BSON value the Realm is partitioned on.

    clientResetMode

    Determines file recovery behavior during a client reset. .recoverUnsyncedChanges by default.

    cancelAsyncOpenOnNonFatalErrors

    By default, Realm.asyncOpen() swallows non-fatal connection errors such as a connection attempt timing out and simply retries until it succeeds. If this is set to true, instead the error will be reported to the callback and the async open will be cancelled.

  • Create a sync configuration instance.

    Declaration

    Swift

    @preconcurrency
    func configuration(partitionValue: AnyBSON,
                       clientResetMode: ClientResetMode = .recoverUnsyncedChanges(beforeReset: nil, afterReset: nil),
                       cancelAsyncOpenOnNonFatalErrors: Bool = false) -> Realm.Configuration

    Parameters

    partitionValue

    Takes nil as a partition value.

    clientResetMode

    Determines file recovery behavior during a client reset. .recoverUnsyncedChanges by default.

    cancelAsyncOpenOnNonFatalErrors

    By default, Realm.asyncOpen() swallows non-fatal connection errors such as a connection attempt timing out and simply retries until it succeeds. If this is set to true, instead the error will be reported to the callback and the async open will be cancelled.

  • The custom data of the user. This is configured in your Atlas App Services app.

    Declaration

    Swift

    var customData: Document { get }
  • A client for interacting with a remote MongoDB instance

    Declaration

    Swift

    func mongoClient(_ serviceName: String) -> MongoClient

    Parameters

    serviceName

    The name of the MongoDB service

    Return Value

    A MongoClient which is used for interacting with a remote MongoDB service

  • Call an Atlas App Services function with the provided name and arguments.

    user.functions.sum([1, 2, 3, 4, 5]) { sum, error in
        guard case let .int64(value) = sum else {
            print(error?.localizedDescription)
        }
    
        assert(value == 15)
    }
    

    The dynamic member name (sum in the above example) is directly associated with the function name. The first argument is the BSONArray of arguments to be provided to the function. The second and final argument is the completion handler to call when the function call is complete. This handler is executed on a non-main global DispatchQueue.

    Declaration

    Swift

    var functions: Functions { get }
  • Refresh a user’s custom data. This will, in effect, refresh the user’s auth session. @returns A publisher that eventually return Dictionary with user’s data or Error.

    Declaration

    Swift

    func refreshCustomData() -> Future<[AnyHashable : Any], Error>
  • Removes the user This logs out and destroys the session related to this user. The completion block will return an error if the user is not found or is already removed. @returns A publisher that eventually return Result.success or Error.

    Declaration

    Swift

    func remove() -> Future<Void, Error>
  • Logs out the current user The users state will be set to Removed is they are an anonymous user or LoggedOut if they are authenticated by a username / password or third party auth clients / If the logout request fails, this method will still clear local authentication state. @returns A publisher that eventually return Result.success or Error.

    Declaration

    Swift

    func logOut() -> Future<Void, Error>
  • Permanently deletes this user from your Atlas App Services app. The users state will be set to Removed and the session will be destroyed. If the delete request fails, the local authentication state will be untouched. @returns A publisher that eventually return Result.success or Error.

    Declaration

    Swift

    func delete() -> Future<Void, Error>
  • A publisher that emits Void each time the user changes.

    Despite the name, this actually emits after the user has changed.

    Declaration

    Swift

    public var objectWillChange: AnyPublisher<UserPublisher.Output, UserPublisher.Failure> { get }
  • Refresh a user’s custom data. This will, in effect, refresh the user’s auth session. @completion A completion that eventually return Result.success(Dictionary) with user’s data or Result.failure(Error).

    Declaration

    Swift

    @preconcurrency
    func refreshCustomData(_ completion: @escaping @Sendable (Result<[AnyHashable : Any], Error>) -> Void)
  • Create a flexible sync configuration instance, which can be used to open a realm which supports flexible sync.

    It won’t be possible to combine flexible and partition sync in the same app, which means if you open a realm with a flexible sync configuration, you won’t be able to open a realm with a PBS configuration and the other way around.

    Declaration

    Swift

    public func flexibleSyncConfiguration(clientResetMode: ClientResetMode = .recoverUnsyncedChanges(),
                                          cancelAsyncOpenOnNonFatalErrors: Bool = false) -> Realm.Configuration

    Parameters

    clientResetMode

    Determines file recovery behavior during a client reset. .recoverUnsyncedChanges by default.

    cancelAsyncOpenOnNonFatalErrors

    By default, Realm.asyncOpen() swallows non-fatal connection errors such as a connection attempt timing out and simply retries until it succeeds. If this is set to true, instead the error will be reported to the callback and the async open will be cancelled.

  • Create a flexible sync configuration instance, which can be used to open a realm which supports flexible sync.

    It won’t be possible to combine flexible and partition sync in the same app, which means if you open a realm with a flexible sync configuration, you won’t be able to open a realm with a PBS configuration and the other way around.

    Using rerunOnOpen covers the cases where you want to re-run dynamic queries, for example time ranges.

    var config = user.flexibleSyncConfiguration(initialSubscriptions: { subscriptions in
        subscriptions.append(QuerySubscription<User>() {
            $0.birthdate < Date() && $0.birthdate > Calendar.current.date(byAdding: .year, value: 21)!
        })
    }, rerunOnOpen: true)
    

    Declaration

    Swift

    @preconcurrency
    public func flexibleSyncConfiguration(clientResetMode: ClientResetMode = .recoverUnsyncedChanges(),
                                          cancelAsyncOpenOnNonFatalErrors: Bool = false,
                                          initialSubscriptions: @escaping @Sendable (SyncSubscriptionSet) -> Void,
                                          rerunOnOpen: Bool = false) -> Realm.Configuration

    Parameters

    clientResetMode

    Determines file recovery behavior during a client reset. .recoverUnsyncedChanges by default.

    initialSubscriptions

    A block which receives a subscription set instance, that can be used to add an initial set of subscriptions which will be executed when the Realm is first opened.

    rerunOnOpen

    If true, allows to run the initial set of subscriptions specified, on every app startup. This can be used to re-run dynamic time ranges and other queries that require a re-computation of a static variable.

    cancelAsyncOpenOnNonFatalErrors

    By default, Realm.asyncOpen() swallows non-fatal connection errors such as a connection attempt timing out and simply retries until it succeeds. If this is set to true, instead the error will be reported to the callback and the async open will be cancelled.