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 }

Lifecycle

Sessions

Custom Data

  • 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 or LoggedOut 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.