RLMUser
Objective-C
@interface RLMUser : NSObject
Swift
@_nonSendable(_assumed) class RLMUser : NSObject, @unchecked Sendable
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 an Atlas App Services 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 Atlas App Services string identifying this user. Note this is different from an identity: A user may have multiple identities but has a single identifier. 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 App Services.
By default, refresh tokens expire 60 days after they are issued. You can configure this time for your App’s refresh tokens to be anywhere between 30 minutes and 180 days.
You can configure the refresh token expiration time for all sessions in an App from the Admin UI or Admin API.
Declaration
Objective-C
@property (nonatomic, readonly, nullable) NSString *refreshToken;
Swift
var refreshToken: String? { get }
-
The user’s access token used to access App Services.
This is required to make HTTP requests to Atlas App Services like the Data API or GraphQL. It should be treated as sensitive data.
The Realm SDK automatically manages access tokens and refreshes them when they expire.
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 partition-based sync configuration instance for the given partition value.
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.
-
Create a partition-based sync configuration instance for the given partition value.
Declaration
Objective-C
- (nonnull RLMRealmConfiguration *) configurationWithPartitionValue:(nullable id<RLMBSON>)partitionValue clientResetMode:(RLMClientResetMode)clientResetMode;
Parameters
partitionValue
The
RLMBSON
value the Realm is partitioned on.clientResetMode
Determines file recovery behavior in the event of a client reset. See: https://mongodb.prakticum-team.ru/proxy/docs.mongodb.com/realm/sync/error-handling/client-resets/
Return Value
A configuration object with the sync configuration set to use the given partition value.
-
Create a partition-based sync configuration instance for the given partition value.
Declaration
Objective-C
- (nonnull RLMRealmConfiguration *) configurationWithPartitionValue:(nullable id<RLMBSON>)partitionValue clientResetMode:(RLMClientResetMode)clientResetMode notifyBeforeReset: (nullable RLMClientResetBeforeBlock)beforeResetBlock notifyAfterReset: (nullable RLMClientResetAfterBlock)afterResetBlock;
Parameters
partitionValue
The
RLMBSON
value the Realm is partitioned on.clientResetMode
Determines file recovery behavior in the event of a client reset. See: https://mongodb.prakticum-team.ru/proxy/docs.mongodb.com/realm/sync/error-handling/client-resets/
beforeResetBlock
A callback which notifies prior to a client reset occurring. See:
RLMClientResetBeforeBlock
afterResetBlock
A callback which notifies after a client reset has occurred. See:
RLMClientResetAfterBlock
Return Value
A configuration object with the sync configuration set to use the given partition value.
-
Create a partition-based sync configuration instance for the given partition value.
Declaration
Objective-C
- (nonnull RLMRealmConfiguration *) configurationWithPartitionValue:(nullable id<RLMBSON>)partitionValue clientResetMode:(RLMClientResetMode)clientResetMode manualClientResetHandler: (nullable RLMSyncErrorReportingBlock)manualClientResetHandler;
Parameters
partitionValue
The
RLMBSON
value the Realm is partitioned on.clientResetMode
Determines file recovery behavior in the event of a client reset. See: https://mongodb.prakticum-team.ru/proxy/docs.mongodb.com/realm/sync/error-handling/client-resets/
manualClientResetHandler
An error reporting block that is invoked during a client reset. @See
RLMSyncErrorReportingBlock
andRLMClientResetInfo
Return Value
A configuration object with the sync configuration set to use the given partition value.
-
Create a flexible sync configuration instance, which can be used to open a Realm that supports flexible sync.
Note
A single server-side Device Sync App can sync data with either partition-based realms or flexible sync based realms. In order for an application to contain both partition-based and flexible sync realms, more than one server-side Device Sync App must be used.
Declaration
Objective-C
- (nonnull RLMRealmConfiguration *)flexibleSyncConfiguration;
Return Value
A
RLMRealmConfiguration
instance with a flexible sync configuration. -
Create a flexible sync configuration instance, which can be used to open a Realm that supports flexible sync.
Note
A single server-side Device Sync App can sync data with either partition-based realms or flexible sync based realms. In order for an application to contain both partition-based and flexible sync realms, more than one server-side Device Sync App must be used.
Declaration
Objective-C
- (nonnull RLMRealmConfiguration *) flexibleSyncConfigurationWithClientResetMode: (RLMClientResetMode)clientResetMode notifyBeforeReset: (nullable RLMClientResetBeforeBlock) beforeResetBlock notifyAfterReset: (nullable RLMClientResetAfterBlock) afterResetBlock;
Parameters
clientResetMode
Determines file recovery behavior in the event of a client reset. See: https://mongodb.prakticum-team.ru/proxy/docs.mongodb.com/realm/sync/error-handling/client-resets/
beforeResetBlock
A callback which notifies prior to a client reset occurring. See:
RLMClientResetBeforeBlock
afterResetBlock
A callback which notifies after a client reset has occurred. See:
RLMClientResetAfterBlock
Return Value
A
RLMRealmConfiguration
instance with a flexible sync configuration. -
Create a flexible sync configuration instance, which can be used to open a Realm that supports flexible sync.
Note
A single server-side Device Sync App can sync data with either partition-based realms or flexible sync based realms. In order for an application to contain both partition-based and flexible sync realms, more than one server-side Device Sync App must be used.
Declaration
Objective-C
- (nonnull RLMRealmConfiguration *) flexibleSyncConfigurationWithClientResetMode: (RLMClientResetMode)clientResetMode manualClientResetHandler: (nullable RLMSyncErrorReportingBlock) manualClientResetHandler;
Parameters
clientResetMode
Determines file recovery behavior in the event of a client reset. See: https://mongodb.prakticum-team.ru/proxy/docs.mongodb.com/realm/sync/error-handling/client-resets/
manualClientResetHandler
An error reporting block that is invoked during a client reset. @See
RLMSyncErrorReportingBlock
andRLMClientResetInfo
Return Value
A
RLMRealmConfiguration
instance with a flexible sync configuration. -
Create a flexible sync configuration instance, which can be used to open a Realm that supports flexible sync.
Note
A single server-side Device Sync App can sync data with either partition-based realms or flexible sync based realms. In order for an application to contain both partition-based and flexible sync realms, more than one server-side Device Sync App must be used.
Declaration
Objective-C
- (nonnull RLMRealmConfiguration *) flexibleSyncConfigurationWithInitialSubscriptions: (nonnull RLMFlexibleSyncInitialSubscriptionsBlock)initialSubscriptions rerunOnOpen:(BOOL)rerunOnOpen;
Parameters
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.
Return Value
A
RLMRealmConfiguration
instance with a flexible sync configuration. -
-flexibleSyncConfigurationWithInitialSubscriptions:
rerunOnOpen: clientResetMode: notifyBeforeReset: notifyAfterReset: Create a flexible sync configuration instance, which can be used to open a Realm that supports flexible sync.
Note
A single server-side Device Sync App can sync data with either partition-based realms or flexible sync based realms. In order for an application to contain both partition-based and flexible sync realms, more than one server-side Device Sync App must be used.
Declaration
Objective-C
- (nonnull RLMRealmConfiguration *) flexibleSyncConfigurationWithInitialSubscriptions: (nonnull RLMFlexibleSyncInitialSubscriptionsBlock)initialSubscriptions rerunOnOpen:(BOOL)rerunOnOpen clientResetMode: (RLMClientResetMode)clientResetMode notifyBeforeReset: (nullable RLMClientResetBeforeBlock) beforeResetBlock notifyAfterReset: (nullable RLMClientResetAfterBlock) afterResetBlock;
Parameters
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.
clientResetMode
Determines file recovery behavior in the event of a client reset. See: https://mongodb.prakticum-team.ru/proxy/docs.mongodb.com/realm/sync/error-handling/client-resets/
beforeResetBlock
A callback which notifies prior to a client reset occurring. See:
RLMClientResetBeforeBlock
afterResetBlock
A callback which notifies after a client reset has occurred. See:
RLMClientResetAfterBlock
Return Value
A
RLMRealmConfiguration
instance with a flexible sync configuration. -
-flexibleSyncConfigurationWithInitialSubscriptions:
rerunOnOpen: clientResetMode: manualClientResetHandler: Create a flexible sync configuration instance, which can be used to open a Realm that supports flexible sync.
Note
A single server-side Device Sync App can sync data with either partition-based realms or flexible sync based realms. In order for an application to contain both partition-based and flexible sync realms, more than one server-side Device Sync App must be used.
Declaration
Objective-C
- (nonnull RLMRealmConfiguration *) flexibleSyncConfigurationWithInitialSubscriptions: (nonnull RLMFlexibleSyncInitialSubscriptionsBlock)initialSubscriptions rerunOnOpen:(BOOL)rerunOnOpen clientResetMode: (RLMClientResetMode)clientResetMode manualClientResetHandler: (nullable RLMSyncErrorReportingBlock) manualClientResetHandler;
Parameters
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.
clientResetMode
Determines file recovery behavior in the event of a client reset. See: https://mongodb.prakticum-team.ru/proxy/docs.mongodb.com/realm/sync/error-handling/client-resets/
manualClientResetHandler
An error reporting block that is invoked during a client reset. @See
RLMSyncErrorReportingBlock
andRLMClientResetInfo
Return Value
A
RLMRealmConfiguration
instance with a flexible sync configuration.
-
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;
Swift
func session(forPartitionValue partitionValue: any RLMBSON) -> RLMSyncSession?
-
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 Atlas App Services app.
Declaration
Objective-C
@property (nonatomic, readonly) NS_REFINED_FOR_SWIFT NSDictionary *customData;
-
The profile of the user.
Declaration
Objective-C
@property (nonatomic, readonly) RLMUserProfile *_Nonnull profile;
Swift
var profile: RLMUserProfile { get }
-
Refresh a user’s custom data. This will, in effect, refresh the user’s auth session.
Declaration
Objective-C
- (void)refreshCustomDataWithCompletion: (nonnull RLMUserCustomDataBlock)completion;
-
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() async throws
Parameters
completion
A callback invoked on completion
-
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.Declaration
Objective-C
- (void)deleteWithCompletion:(nonnull RLMUserOptionalErrorBlock)completion;
Swift
func delete() async throws
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() async throws
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 Atlas App Services 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 Atlas App Services 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
.