Search Results for

    Show / Hide Table of Contents

    Class App

    An App is the main client-side entry point for interacting with a Atlas App Services application.

    The App can be used to:

    • Register uses and perform various user-related operations through authentication providers (e.g. ApiKeys, EmailPasswordAuth).
    • Synchronize data between the local device and a remote Realm App with Synchronized Realms (using SyncConfigurationBase).
    • Invoke Realm App functions with Functions (using Functions).
    • Access remote data from MongoDB databases with a MongoClient (using GetMongoClient(string)).

    To create an app that is linked with a remote Realm App initialize Realm and configure the App as shown below:
    var appConfig = new AppConfiguration("my-realm-app-id");
    var app = new App(appConfig);
    After configuring the App you can start managing users, configure Synchronized Realms, call remote Realm Functions, and access remote data through Mongo Collections.
    To register a new user and/or login with an existing user do as shown below:
    await app.EmailPassword.RegisterUserAsync("foo@bar.com", "password");
    // Login with existing user
    var user = app.LoginAsync(Credentials.EmailPassword("foo@bar.com", "password");
    With an authorized user you can synchronize data between the local device and the remote Realm App by opening a Realm with a SyncConfigurationBase as indicated below:
    var syncConfig = new PartitionSyncConfiguration("some-partition-value", user);
    using var realm = await Realm.GetInstanceAsync(syncConfig);
    

    realm.Write(() => { realm.Add(...); });

    await realm.GetSession().WaitForUploadAsync();

    You can call remote Realm functions as shown below:
    var result = await user.Functions.CallAsync<int>("sum", 1, 2, 3, 4, 5);

    And access collections from the remote Realm App as shown here:

    var client = user.GetMongoClient("atlas-service");
    var db = client.GetDatabase("my-db");
    var collection = db.GetCollection("foos");
    var foosCount = await collection.CountAsync();
    Inheritance
    object
    App
    Namespace: Realms.Sync
    Assembly: Realm.dll
    Syntax
    public class App

    Properties

    | Edit this page View Source

    AllUsers

    Gets all currently logged in users.

    Declaration
    public User[] AllUsers { get; }
    Property Value
    Type Description
    User[]

    An array of valid logged in users.

    | Edit this page View Source

    BaseFilePath

    Gets the root folder relative to which all local data for this application will be stored. This data includes metadata for users and synchronized Realms.

    Declaration
    public string BaseFilePath { get; }
    Property Value
    Type Description
    string

    The app's base path.

    See Also
    BaseFilePath
    | Edit this page View Source

    BaseUri

    Gets the base url for this Realm application.

    Declaration
    public Uri BaseUri { get; }
    Property Value
    Type Description
    Uri

    The app's base url.

    See Also
    BaseUri
    | Edit this page View Source

    CurrentUser

    Gets the currently user. If none exists, null is returned.

    Declaration
    public User? CurrentUser { get; }
    Property Value
    Type Description
    User

    Valid user or null to indicate nobody logged in.

    | Edit this page View Source

    EmailPasswordAuth

    Gets a App.EmailPasswordClient instance that exposes functionality related to users either being created or logged in using the EmailPassword provider.

    Declaration
    public App.EmailPasswordClient EmailPasswordAuth { get; }
    Property Value
    Type Description
    App.EmailPasswordClient

    An App.EmailPasswordClient instance scoped to this App.

    | Edit this page View Source

    Id

    Gets the unique app id that identifies the Realm application.

    Declaration
    public string Id { get; }
    Property Value
    Type Description
    string

    The Atlas App Services App's id.

    | Edit this page View Source

    Sync

    Gets a App.SyncClient instance that exposes API for interacting with the synchronization client for this App.

    Declaration
    public App.SyncClient Sync { get; }
    Property Value
    Type Description
    App.SyncClient

    A App.SyncClient instance scoped to this App.

    Methods

    | Edit this page View Source

    Create(AppConfiguration)

    A factory method for creating an app with a particular AppConfiguration.

    Declaration
    public static App Create(AppConfiguration config)
    Parameters
    Type Name Description
    AppConfiguration config

    The AppConfiguration, specifying key parameters for the app behavior.

    Returns
    Type Description
    App

    An App instance can now be used to login users, call functions, or open synchronized Realms.

    | Edit this page View Source

    Create(string)

    A factory method for creating an app with a particular app Id.

    Declaration
    public static App Create(string appId)
    Parameters
    Type Name Description
    string appId

    The application id of the Atlas App Services Application.

    Returns
    Type Description
    App

    An App instance can now be used to login users, call functions, or open synchronized Realms.

    Remarks

    This is a convenience method that creates an AppConfiguration with the default parameters and the provided appId and invokes Create(AppConfiguration).

    | Edit this page View Source

    DeleteUserFromServerAsync(User)

    Deletes a user from the server. The user is also removed from the device together with their local data. If the user is logged in, they will be logged out in the process.

    Declaration
    public Task DeleteUserFromServerAsync(User user)
    Parameters
    Type Name Description
    User user

    The user to remove from the server.

    Returns
    Type Description
    Task

    An awaitable Task that represents the asynchronous deletion operation. Successful completion indicates that the user has been removed, logged out and their local data has been removed.

    | Edit this page View Source

    LogInAsync(Credentials)

    Logs in as a user with the given credentials associated with an authentication provider.

    Declaration
    public Task<User> LogInAsync(Credentials credentials)
    Parameters
    Type Name Description
    Credentials credentials

    The Credentials representing the type of login.

    Returns
    Type Description
    Task<User>

    An awaitable Task<TResult> that represents the asynchronous LogIn operation.

    Remarks

    The last logged in user will be saved as CurrentUser. If there was already a current user, that user is still logged in and can be found in the list returned by AllUsers. It is also possible to switch between which user is considered the current user by using SwitchUser(User).

    | Edit this page View Source

    RemoveUserAsync(User)

    Removes a user and their local data from the device. If the user is logged in, they will be logged out in the process.

    Declaration
    public Task RemoveUserAsync(User user)
    Parameters
    Type Name Description
    User user

    The user to log out and remove.

    Returns
    Type Description
    Task

    An awaitable Task that represents the asynchronous RemoveUser operation. Successful completion indicates that the user has been logged out, their local data - removed, and the user's RefreshToken - revoked on the server.

    Remarks

    This is client operation and will not delete any data stored on the server for that user.

    | Edit this page View Source

    SwitchUser(User)

    Switches the CurrentUser to the one specified in user.

    Declaration
    public void SwitchUser(User user)
    Parameters
    Type Name Description
    User user

    The new current user.

    | Edit this page View Source

    UpdateBaseUriAsync(Uri?)

    Temporarily overrides the BaseUri value from AppConfiguration with a new newUri value used for communicating with the server.

    Declaration
    public Task UpdateBaseUriAsync(Uri? newUri)
    Parameters
    Type Name Description
    Uri newUri

    The new uri that will be used for communicating with the server. If set to null, the base uri will be reset to its default value.

    Returns
    Type Description
    Task

    An awaitable Task that represents the asynchronous operation.

    Remarks

    The App will revert to using the value in [AppConfiguration] when it is restarted.
    This API must be called after sync sessions have been manually stopped and at a point where the server at newUri is reachable. Once the base uri has been updated, sync sessions should be resumed and the user needs to reauthenticate.
    This API is experimental and subject to change without a major version increase.

    Operators

    | Edit this page View Source

    operator ==(App?, App?)

    Determines whether two App instances are equal.

    Declaration
    public static bool operator ==(App? app1, App? app2)
    Parameters
    Type Name Description
    App app1

    The first app to compare.

    App app2

    The second app to compare.

    Returns
    Type Description
    bool

    true if the two instances are equal; false otherwise.

    | Edit this page View Source

    operator !=(App?, App?)

    Determines whether two App instances are different.

    Declaration
    public static bool operator !=(App? app1, App? app2)
    Parameters
    Type Name Description
    App app1

    The first app to compare.

    App app2

    The second app to compare.

    Returns
    Type Description
    bool

    true if the two instances are different; false otherwise.

    • Edit this page
    • View Source
    In this article
    Back to top Copyright © 2020-2024 Realm
    Generated by DocFX