RLMSyncUser

@interface RLMSyncUser : NSObject

A RLMSyncUser instance represents a single Realm Object Server user account.

A user may have one or more credentials associated with it. These credentials uniquely identify the user to the authentication provider, and are used to sign into a Realm Object Server user account.

Note that user objects are only vended out via SDK APIs, and cannot be directly initialized. User objects can be accessed from any thread.

  • A dictionary of all valid, logged-in user identities corresponding to their user objects.

    Declaration

    Objective-C

    + (nonnull NSDictionary<NSString *, RLMSyncUser *> *)allUsers;

    Swift

    class func __allUsers() -> [String : RLMSyncUser]
  • The logged-in user. nil if none exists.

    Warning

    Throws an exception if more than one logged-in user exists.

    Declaration

    Objective-C

    + (nullable RLMSyncUser *)currentUser;

    Swift

    class func __current() -> RLMSyncUser?
  • The unique Realm Object Server user ID string identifying this user.

    Declaration

    Objective-C

    @property (readonly, nonatomic, nullable) NSString *identity;

    Swift

    var identity: String? { get }
  • The URL of the authentication server this user will communicate with.

    Declaration

    Objective-C

    @property (readonly, nonatomic, nullable) NSURL *authenticationServer;

    Swift

    var authenticationServer: URL? { get }
  • Whether the user is a Realm Object Server administrator. Value reflects the state at the time of the last successful login of this user.

    Declaration

    Objective-C

    @property (readonly, nonatomic) BOOL isAdmin;

    Swift

    var isAdmin: Bool { get }
  • The current state of the user.

    Declaration

    Objective-C

    @property (readonly, nonatomic) RLMSyncUserState state;

    Swift

    var state: RLMSyncUserState { get }
  • Create, log in, and asynchronously return a new user object, specifying a custom timeout for the network request. Credentials identifying the user must be passed in. The user becomes available in the completion block, at which point it is ready for use.

    Declaration

    Objective-C

    + (void)logInWithCredentials:(nonnull RLMSyncCredentials *)credentials
                   authServerURL:(nonnull NSURL *)authServerURL
                         timeout:(NSTimeInterval)timeout
                    onCompletion:(nonnull RLMUserCompletionBlock)completion;

    Swift

    class func __logIn(with credentials: RLMSyncCredentials, authServerURL: URL, timeout: TimeInterval, onCompletion completion: @escaping RLMUserCompletionBlock)
  • Create, log in, and asynchronously return a new user object. Credentials identifying the user must be passed in. The user becomes available in the completion block, at which point it is ready for use.

    Declaration

    Objective-C

    + (void)logInWithCredentials:(nonnull RLMSyncCredentials *)credentials
                   authServerURL:(nonnull NSURL *)authServerURL
                    onCompletion:(nonnull RLMUserCompletionBlock)completion;
  • Log a user out, destroying their server state, unregistering them from the SDK, and removing any synced Realms associated with them from on-disk storage on next app launch. If the user is already logged out or in an error state, this method does nothing.

    This method should be called whenever the application is committed to not using a user again unless they are recreated. Failing to call this method may result in unused files and metadata needlessly taking up space.

    Declaration

    Objective-C

    - (void)logOut;

    Swift

    func logOut()
  • Change this user’s password asynchronously.

    Warning

    Changing a user’s password using an authentication server that doesn’t use HTTPS is a major security flaw, and should only be done while testing.

    Declaration

    Objective-C

    - (void)changePassword:(nonnull NSString *)newPassword
                completion:(nonnull RLMPasswordChangeStatusBlock)completion;

    Swift

    func changePassword(_ newPassword: String, completion: @escaping RLMPasswordChangeStatusBlock)

    Parameters

    newPassword

    The user’s new password.

    completion

    Completion block invoked when login has completed or failed. The callback will be invoked on a background queue provided by NSURLSession.

  • Change an arbitrary user’s password asynchronously.

    Note

    The current user must be an admin user for this operation to succeed.

    Warning

    Changing a user’s password using an authentication server that doesn’t use HTTPS is a major security flaw, and should only be done while testing.

    Declaration

    Objective-C

    - (void)changePassword:(nonnull NSString *)newPassword
                 forUserID:(nonnull NSString *)userID
                completion:(nonnull RLMPasswordChangeStatusBlock)completion;

    Swift

    func changePassword(_ newPassword: String, forUserID userID: String, completion: @escaping RLMPasswordChangeStatusBlock)

    Parameters

    newPassword

    The user’s new password.

    userID

    The identity of the user whose password should be changed.

    completion

    Completion block invoked when login has completed or failed. The callback will be invoked on a background queue provided by NSURLSession.

  • Returns an instance of the Management Realm owned by the user.

    This Realm can be used to control access permissions for Realms managed by the user. This includes granting other users access to Realms.

    Declaration

    Objective-C

    - (nonnull RLMRealm *)managementRealmWithError:
        (NSError *_Nullable *_Nullable)error;

    Swift

    func __managementRealmWithError(_ error: NSErrorPointer) -> RLMRealm
  • Returns an instance of the Permission Realm owned by the user.

    This read-only Realm contains RLMSyncPermission objects reflecting the synchronized Realms and permission details this user has access to.

    Declaration

    Objective-C

    - (nonnull RLMRealm *)permissionRealmWithError:
        (NSError *_Nullable *_Nullable)error;

    Swift

    func __permissionRealmWithError(_ error: NSErrorPointer) -> RLMRealm