Providers
Introduction
<JazzProvider />
is the core component that connects your Expo application to Jazz. It handles:
- Data Synchronization: Manages connections to peers and the Jazz cloud
- Local Storage: Persists data locally between app sessions
- Schema Types: Provides APIs for the AccountSchema
- Authentication: Connects your authentication system to Jazz
Setting up the provider
Wrap your app components with the <JazzProvider />
component:
// App.tsx import {
function JazzProvider(props: JazzProviderProps): React.JSX.Element
JazzProvider } from "jazz-expo"; import {import MyAppAccount
MyAppAccount } from "./schema"; export functionMyJazzProvider({
function MyJazzProvider({ children }: { children: React.ReactNode; }): React.JSX.Element
children: React.ReactNode
children }: {children: React.ReactNode
children:export namespace React
React.type React.ReactNode = string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | React.ReactPortal | null | undefined
Represents all of the things React can render. Where {@link ReactElement } only represents JSX, `ReactNode` represents everything that can be rendered.ReactNode }) { return ( <function JazzProvider(props: JazzProviderProps): React.JSX.Element
JazzProvidersync: SyncConfig
sync={{peer: "wss://cloud.jazz.tools/?key=you@example.com"
peer: "wss://cloud.jazz.tools/?key=you@example.com" }}AccountSchema?: AccountClass<MyAppAccount> | undefined
AccountSchema={import MyAppAccount
MyAppAccount} > {children: React.ReactNode
children} </function JazzProvider(props: JazzProviderProps): React.JSX.Element
JazzProvider> ); } // Register the Account schema so `useAccount` returns our custom `MyAppAccount` declare module "jazz-expo" { interface Register {Register.Account: MyAppAccount
Account:import MyAppAccount
MyAppAccount; } }
Provider Options
kvStore
ExpoSecureStoreAdapter
(default)
AccountSchema
Account
(default)
CryptoProvider
PureJSCrypto
(default) - Pure JavaScript crypto providerRNQuickCrypto
- C++ accelerated crypto provider
Authentication in the Provider
<JazzProvider />
works with various authentication methods, with PassphraseAuth being the easiest way to get started for development and testing. For authentication details, refer to our Authentication Overview guide.
The authentication hooks must always be used inside the <JazzProvider />
component.
Implementing PassphraseAuth is straightforward:
- Import the wordlist for generating recovery phrases
- Use the
usePassphraseAuth
hook to handle authentication - Create simple registration and sign-in screens
// Example with PassphraseAuth import {
function JazzProvider(props: JazzProviderProps): React.JSX.Element
JazzProvider,
function usePassphraseAuth({ wordlist, }: { wordlist: string[]; }): { readonly state: "signedIn" | "anonymous"; readonly logIn: (passphrase: string) => Promise<void>; readonly signUp: (name?: string) => Promise<string>; readonly registerNewAccount: (passphrase: string, name: string) => Promise<import("/vercel/path0/packages/jazz-tools/dist/internal").ID<import("/vercel/path0/packages/jazz-tools/dist/exports").Account>>; readonly generateRandomPassphrase: () => string; readonly passphrase: string; }
`usePassphraseAuth` hook provides a `JazzAuth` object for passphrase authentication.usePassphraseAuth } from "jazz-expo"; import {import englishWordlist
englishWordlist } from "./wordlist"; functionJazzAuthentication({
function JazzAuthentication({ children }: { children: ReactNode; }): string | number | boolean | Iterable<React.ReactNode> | React.JSX.Element | null | undefined
children: React.ReactNode
children }: {children: React.ReactNode
children:type ReactNode = string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | React.ReactPortal | null | undefined
Represents all of the things React can render. Where {@link ReactElement } only represents JSX, `ReactNode` represents everything that can be rendered.ReactNode }) { constauth =
const auth: { readonly state: "signedIn" | "anonymous"; readonly logIn: (passphrase: string) => Promise<void>; readonly signUp: (name?: string) => Promise<string>; readonly registerNewAccount: (passphrase: string, name: string) => Promise<import("/vercel/path0/packages/jazz-tools/dist/internal").ID<import("/vercel/path0/packages/jazz-tools/dist/exports").Account>>; readonly generateRandomPassphrase: () => string; readonly passphrase: string; }
function usePassphraseAuth({ wordlist, }: { wordlist: string[]; }): { readonly state: "signedIn" | "anonymous"; readonly logIn: (passphrase: string) => Promise<void>; readonly signUp: (name?: string) => Promise<string>; readonly registerNewAccount: (passphrase: string, name: string) => Promise<import("/vercel/path0/packages/jazz-tools/dist/internal").ID<import("/vercel/path0/packages/jazz-tools/dist/exports").Account>>; readonly generateRandomPassphrase: () => string; readonly passphrase: string; }
`usePassphraseAuth` hook provides a `JazzAuth` object for passphrase authentication.usePassphraseAuth({wordlist: string[]
wordlist:import englishWordlist
englishWordlist, }); // If the user is already signed in, render the App if (auth.
const auth: { readonly state: "signedIn" | "anonymous"; readonly logIn: (passphrase: string) => Promise<void>; readonly signUp: (name?: string) => Promise<string>; readonly registerNewAccount: (passphrase: string, name: string) => Promise<import("/vercel/path0/packages/jazz-tools/dist/internal").ID<import("/vercel/path0/packages/jazz-tools/dist/exports").Account>>; readonly generateRandomPassphrase: () => string; readonly passphrase: string; }
state: "signedIn" | "anonymous"
state === "signedIn") { returnchildren: React.ReactNode
children } // Otherwise, show a sign-in screen return <SignInScreen
function SignInScreen({ auth }: { auth: any; }): null
auth: any
auth={auth} />; } function
const auth: { readonly state: "signedIn" | "anonymous"; readonly logIn: (passphrase: string) => Promise<void>; readonly signUp: (name?: string) => Promise<string>; readonly registerNewAccount: (passphrase: string, name: string) => Promise<import("/vercel/path0/packages/jazz-tools/dist/internal").ID<import("/vercel/path0/packages/jazz-tools/dist/exports").Account>>; readonly generateRandomPassphrase: () => string; readonly passphrase: string; }
AuthenticatedProvider({
function AuthenticatedProvider({ children }: { children: ReactNode; }): React.JSX.Element
children: React.ReactNode
children }: {children: React.ReactNode
children:type ReactNode = string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | React.ReactPortal | null | undefined
Represents all of the things React can render. Where {@link ReactElement } only represents JSX, `ReactNode` represents everything that can be rendered.ReactNode }) { return ( <function JazzProvider(props: JazzProviderProps): React.JSX.Element
JazzProvidersync: SyncConfig
sync={{peer: "wss://cloud.jazz.tools/?key=your-api-key"
peer: "wss://cloud.jazz.tools/?key=your-api-key" }} > <JazzAuthentication> {
function JazzAuthentication({ children }: { children: ReactNode; }): string | number | boolean | Iterable<React.ReactNode> | React.JSX.Element | null | undefined
children: React.ReactNode
children} </JazzAuthentication> </
function JazzAuthentication({ children }: { children: ReactNode; }): string | number | boolean | Iterable<React.ReactNode> | React.JSX.Element | null | undefined
function JazzProvider(props: JazzProviderProps): React.JSX.Element
JazzProvider> ); }
For a complete example, see the Expo Chat Demo.
Local Persistence
Jazz for Expo includes built-in local persistence using SQLite. Following Expo's best practices, the Expo implementation uses:
- Database Storage:
expo-sqlite
- Expo's official SQLite module - Key-Value Storage:
expo-secure-store
- Expo's secure storage system
Local persistence is enabled by default with no additional configuration required. Your data will automatically persist across app restarts.