Join us at MongoDB.local London on 7 May to unlock new possibilities for your data. Use WEB50 to save 50%.
Register now >
Docs Menu
Docs Home
/ /
Atlas App Services

Conectarse a una aplicación Atlas App Services - SDK de React Native

The App client is the interface to the App Services backend. It provides access to the authentication functionality, Atlas Functions, and Atlas Device Sync.

  1. Crear una aplicación de servicios de aplicaciones

  2. Get Your App ID

Para configurar su cliente de aplicación, pase la cadena de ID de la aplicación a id AppProviderpropiedad de. Envuelva cualquier componente que necesite acceder a la aplicación AppProvider con. En este ejemplo, envolvemos UserProvider en AppProvider para autenticar a un usuario.

import React from 'react';
import {AppProvider, UserProvider} from '@realm/react';
export const AppWithAuthHook = () => {
return (
<View>
<AppProvider id={APP_ID}>
<UserProvider fallback={LogIn}>
<MyApp />
</UserProvider>
</AppProvider>
</View>
);
};

Puedes crear varias instancias de un cliente de aplicación para conectarte a múltiples aplicaciones. Todas las instancias de cliente de aplicación que comparten el mismo ID de la aplicación utilizan la misma conexión subyacente.

Importante

Changing an App Config After Initializing the App

Cambiado en la versión realm@12.6.0: baseUrl no está almacenado en caché

Cuando inicias el cliente de la aplicación, la configuración se almacena en caché internamente. El intentar "cerrar" y luego reabrir una aplicación con una configuración modificada dentro del mismo proceso no tiene efecto. El cliente continúa utilizando la configuración almacenada en caché.

Starting with React Native SDK version 12.6.0, the baseUrl in the AppConfiguration is not cached. This means that you can change the baseUrl and the App client will use the updated configuration. In earlier SDK versions, changes to the baseUrl in a cached App configuration have no effect.

All components wrapped within an AppProvider can access the App client with the useApp() hook.

import React from 'react';
import {useApp} from '@realm/react';
function MyApp() {
const app = useApp();
// Proceed to app logic...
}

To retrieve an instance of the App Client from anywhere in your application, instantiate a new instance of Realm.App() from the realm package, then pass in your App ID.

import Realm from 'realm';
const app = Realm.App.getApp("<Your App ID>");

Puedes cifrar los metadatos que aplicación Services almacena en los dispositivos de los clientes. Utiliza los valores del enumerado MetadataMode para determinar el comportamiento de cifrado.

Para cifrar los metadatos de la aplicación:

  1. Importa MetadataMode desde Realm e importa otras dependencias:

    import React from 'react';
    import {Text, View} from 'react-native';
    import {MetadataMode} from 'realm';
    import {AppProvider} from '@realm/react';
  2. Create an App configuration object that contains the metadata property.

  3. Establezca metadata.mode en MetadataMode.Encryption.

  4. Configura metadata.encryptionKey como la clave que deseas usar para el cifrado.

  5. Pass the App configuration object to new Realm.App().

const EncryptMetadata = ({
encryptionKey,
}: {
encryptionKey: ArrayBuffer;
}) => {
const metadataConfig = {
mode: MetadataMode.Encryption,
encryptionKey: encryptionKey,
};
return (
<AppProvider
id={APP_ID}
metadata={metadataConfig}>
<RestOfApp />
</AppProvider>
);
};

Volver

Atlas App Services

En esta página