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()
-
Retrieve a valid session object belonging to this user for a given URL, or
nil
if no such object exists.Declaration
Objective-C
- (nullable RLMSyncSession *)sessionForURL:(nonnull NSURL *)url;
Swift
func session(for url: URL) -> RLMSyncSession?
-
Retrieve all the valid sessions belonging to this user.
Declaration
Objective-C
- (nonnull NSArray<RLMSyncSession *> *)allSessions;
Swift
func allSessions() -> [RLMSyncSession]
-
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
.
-
Asynchronously retrieve all permissions associated with the user calling this method.
The results will be returned through the callback block, or an error if the operation failed. The callback block will be run on the same thread the method was called on.
Warning
This method must be called from a thread with a currently active run loop. Unless you have manually configured a run loop on a side thread, this will usually be the main thread.
Declaration
Objective-C
- (void)retrievePermissionsWithCallback: (nonnull RLMPermissionResultsBlock)callback;
Swift
func retrievePermissions(callback: @escaping RLMPermissionResultsBlock)
-
Apply a given permission.
The operation will take place asynchronously, and the callback will be used to report whether the permission change succeeded or failed. The user calling this method must have the right to grant the given permission, or else the operation will fail.
Declaration
Objective-C
- (void)applyPermission:(nonnull RLMSyncPermissionValue *)permission callback:(nonnull RLMPermissionStatusBlock)callback;
Swift
func applyPermission(_ permission: RLMSyncPermissionValue, callback: @escaping RLMPermissionStatusBlock)
-
Revoke a given permission.
The operation will take place asynchronously, and the callback will be used to report whether the permission change succeeded or failed. The user calling this method must have the right to grant the given permission, or else the operation will fail.
Declaration
Objective-C
- (void)revokePermission:(nonnull RLMSyncPermissionValue *)permission callback:(nonnull RLMPermissionStatusBlock)callback;
Swift
func revokePermission(_ permission: RLMSyncPermissionValue, callback: @escaping RLMPermissionStatusBlock)
-
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.
-
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.