RLMUser
@interface RLMUser : NSObject
A RLMUser
instance represents a single Realm App 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 MongoDB Realm 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.
-
The unique MongoDB Realm string identifying this user. Note this is different from an identitiy: A user may have multiple identities but has a single indentifier. See RLMUserIdentity.
Declaration
Objective-C
@property (nonatomic, readonly) NS_SWIFT_NAME(id) NSString *identifier;
Swift
var id: String { get }
-
Returns an array of identities currently linked to a user.
Declaration
Objective-C
@property (nonatomic, readonly) NSArray<RLMUserIdentity *> *_Nonnull identities;
Swift
var identities: [RLMUserIdentity] { get }
-
The user’s refresh token used to access the Realm Applcation.
This is required to make HTTP requests to the Realm App’s REST API for functionality not exposed natively. It should be treated as sensitive data.
Declaration
Objective-C
@property (nonatomic, readonly, nullable) NSString *refreshToken;
Swift
var refreshToken: String? { get }
-
The user’s refresh token used to access the Realm Application.
This is required to make HTTP requests to MongoDB Realm’s REST API for functionality not exposed natively. It should be treated as sensitive data.
Declaration
Objective-C
@property (nonatomic, readonly, nullable) NSString *accessToken;
Swift
var accessToken: String? { get }
-
The current state of the user.
Declaration
Objective-C
@property (nonatomic, readonly) RLMUserState state;
Swift
var state: RLMUserState { get }
-
Indicates if the user is logged in or not. Returns true if the access token and refresh token are not empty.
Declaration
Objective-C
@property (nonatomic, readonly) BOOL isLoggedIn;
Swift
var isLoggedIn: Bool { get }
-
Create a query-based configuration instance for the given url.
Declaration
Objective-C
- (nonnull RLMRealmConfiguration *)configurationWithPartitionValue: (nullable id<RLMBSON>)partitionValue;
Parameters
partitionValue
The
RLMBSON
value the Realm is partitioned on.Return Value
A default configuration object with the sync configuration set to use the given partition value.
-
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 *)sessionForPartitionValue: (nonnull id<RLMBSON>)partitionValue;
-
Retrieve all the valid sessions belonging to this user.
Declaration
Objective-C
@property (nonatomic, readonly) NSArray<RLMSyncSession *> *_Nonnull allSessions;
Swift
var allSessions: [RLMSyncSession] { get }
-
The custom data of the user. This is configured in your MongoDB Realm App.
Declaration
Objective-C
@property (nonatomic, readonly) NS_REFINED_FOR_SWIFT NSDictionary *customData;
-
Refresh a user’s custom data. This will, in effect, refresh the user’s auth session.
Declaration
Objective-C
- (void)refreshCustomDataWithCompletion: (nonnull RLMUserCustomDataBlock)completion;
Swift
func refreshCustomData(completion: @escaping RLMUserCustomDataBlock)
-
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
RLMUser
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
Objective-C
- (void)linkUserWithCredentials:(nonnull RLMCredentials *)credentials completion:(nonnull RLMOptionalUserBlock)completion;
Parameters
credentials
The
RLMCredentials
used to link the user to a new identity.completion
The completion handler to call when the linking is complete. If the operation is successful, the result will contain a new
RLMUser
object representing the currently logged in user. -
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.
Declaration
Objective-C
- (void)removeWithCompletion:(nonnull RLMUserOptionalErrorBlock)completion;
Swift
func remove(completion: @escaping RLMUserOptionalErrorBlock)
Parameters
completion
A callback invoked on completion
-
Logs out the current user
The users state will be set to
Removed
is they are an anonymous user orLoggedOut
if they are authenticated by an email / password or third party auth clients If the logout request fails, this method will still clear local authentication state.Declaration
Objective-C
- (void)logOutWithCompletion:(nonnull RLMUserOptionalErrorBlock)completion;
Swift
func logOut(completion: @escaping RLMUserOptionalErrorBlock)
Parameters
completion
A callback invoked on completion
-
A client for the user API key authentication provider which can be used to create and modify user API keys.
This client should only be used by an authenticated user.
Declaration
Objective-C
@property (nonatomic, readonly) RLMAPIKeyAuth *_Nonnull apiKeysAuth;
Swift
var apiKeysAuth: RLMAPIKeyAuth { get }
-
A client for interacting with a remote MongoDB instance
Declaration
Objective-C
- (nonnull RLMMongoClient *)mongoClientWithServiceName: (nonnull NSString *)serviceName;
Parameters
serviceName
The name of the MongoDB service
-
Calls the MongoDB Realm function with the provided name and arguments.
Declaration
Objective-C
- (void)callFunctionNamed:(nonnull NSString *)name arguments:(nonnull NSArray<id<RLMBSON>> *)arguments completionBlock:(nonnull RLMCallFunctionCompletionBlock)completion;
Parameters
name
The name of the MongoDB Realm function to be called.
arguments
The
BSONArray
of arguments to be provided to the function.completion
The completion handler to call when the function call is complete. This handler is executed on a non-main global
DispatchQueue
.