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.

    Inheritance
    Object
    App
    Namespace: Realms.Sync
    Assembly: Realm.dll
    Syntax
    public class App
    Remarks

    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")
    {
        LocalAppName = "My amazing iOS app",
        LocalAppVersion = "1.2.3"
    };
    
    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();

    Properties

    | Improve this Doc 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.

    | Improve this Doc 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.

    | Improve this Doc 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.

    | Improve this Doc 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

    | Improve this Doc 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.

    | Improve this Doc 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).

    | Improve this Doc 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.

    | Improve this Doc View Source

    LogInAsync(Credentials)

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

    Declaration
    public async 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).

    | Improve this Doc 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.

    | Improve this Doc 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.

    See Also

    AppConfiguration
    • Improve this Doc
    • View Source
    In This Article
    Back to top Copyright © 2020 Realm
    Generated by DocFX