The App client is the interface to the App Services backend. It provides access to the authentication functionality, Atlas Functions, and Atlas Device Sync.
Antes de comenzar
Configure the App Client
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.
Retrieve an Instance of the App Client
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... }
Retrieve App Outside the App Provider
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>");
Encriptar Metadatos de la aplicación
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:
Importa
MetadataModedesdeRealme importa otras dependencias:import React from 'react'; import {Text, View} from 'react-native'; import {MetadataMode} from 'realm'; import {AppProvider} from '@realm/react'; Create an App configuration object that contains the
metadataproperty.Establezca
metadata.modeenMetadataMode.Encryption.Configura
metadata.encryptionKeycomo la clave que deseas usar para el cifrado.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> ); };