@@ -27,6 +27,12 @@ develop a React app using JavaScript-based Atlas Device SDKs. The components lev
27
27
provider design pattern to manage your Atlas connection, user creation and authentication, and
28
28
data management.
29
29
30
+ - :realm-react-sdk:`AppProvider (@realm/react) <functions/AppProvider.html>`
31
+
32
+ - :realm-react-sdk:`UserProvider (@realm/react) <functions/UserProvider.html>`
33
+
34
+ - :realm-react-sdk:`RealmProvider (@realm/react) <functions/RealmProvider.html>`
35
+
30
36
The providers are available in all SDKs that support a React environment. This includes React
31
37
Native, Web, and Electron.
32
38
@@ -99,6 +105,8 @@ Provider has different props you can use for configuration.
99
105
.. tab:: UserProvider Props
100
106
:tabid: user-provider-props
101
107
108
+ The only prop passed into ``UserProvider`` is an optional fallback component:
109
+
102
110
- ``fallback?: React.ComponentType<unknown> | React.ReactElement | null | undefined``
103
111
104
112
The fallback component to render if there is no authorized user. This can be
@@ -110,16 +118,24 @@ Configure your Providers
110
118
Your app's needs determine what providers you use, as all three providers are not always
111
119
necessary:
112
120
113
- - ``AppProvider``: Used to connect to your :js-sdk :`Atlas App Services App Client
114
- <classes/Realm.App-1.html >`, including for user authentication.
121
+ - ``AppProvider``: Used to connect to your :ref :`Atlas App Services App Client
122
+ <create-app >`, including for user authentication.
115
123
116
- - ``UserProvider``: Used to access the logged-in :js-sdk :`user object <classes/Realm.User.html >`.
124
+ - ``UserProvider``: Used to access the logged-in :ref :`user object <user-accounts >`.
117
125
118
- - ``RealmProvider``: Used to work with the configured :js-sdk:` database <classes/Realm-1.html>` .
126
+ - ``RealmProvider``: Used to work with the configured database.
119
127
120
128
The example below walks through configuring all three providers. If your app does not need a
121
129
certain provider, you can skip the steps and omit the code for that provider.
122
130
131
+ .. note:: Exposing more than one database using createRealmContext()
132
+
133
+ The example details how to configure and expose a single database using a ``RealmProvider``
134
+ imported directly from ``@realm/react``.
135
+ For information about using ``createRealmContext()`` to configure a database or exposing more
136
+ than one database, see :ref:`Create Context with createRealmContext()
137
+ <create_context_with_createrealmcontext>` below.
138
+
123
139
**To configure your providers:**
124
140
125
141
1. Import ``RealmProvider``, ``AppProvider``, and ``UserProvider`` from ``@realm/react``.
@@ -146,9 +162,10 @@ certain provider, you can skip the steps and omit the code for that provider.
146
162
147
163
c. Add other configuration object properties as props to ``RealmProvider`` as needed.
148
164
149
- Once your providers have been configured, nest your app components within the
150
- provider whose context it needs to access. Generally, you can nest your components within the
151
- ``RealmProvider`` to ensure they have access to all three providers' contexts.
165
+ 5. Nest you app components in the providers.
166
+ Once your providers have been configured, nest your app components within the
167
+ provider whose context it needs to access. Generally, you can nest your components within the
168
+ ``RealmProvider`` to ensure they have access to all three providers' contexts.
152
169
153
170
The rendering of each component is dependent on the successful
154
171
execution of its parent components' functionality. For example, if ``AppProvider`` cannot
@@ -159,14 +176,6 @@ You *must* nest the providers as shown below to ensure each has access to its re
159
176
.. literalinclude:: /examples/generated/react-native/ts/configure-realm-sync.test.snippet.configure-realm-sync-full.tsx
160
177
:language: javascript
161
178
162
- .. note::
163
-
164
- The example details how to configure and expose a single database using a ``RealmProvider``
165
- imported directly from ``@realm/react``.
166
- For information about using ``createRealmContext()`` to configure a database or exposing more
167
- than one database, see :ref:`Create Context with createRealmContext()
168
- <create_context_with_createrealmcontext>` below.
169
-
170
179
Working with Providers using Hooks
171
180
----------------------------------
172
181
@@ -366,12 +375,12 @@ you the name of the current operation.
366
375
367
376
*Enum values*
368
377
369
- - ``state``. Can be "not-started", "pending", "success", "error".
370
- - ``operation``. For a list of all operation names, refer to the
378
+ - ``state``: Can be `` "not-started"``, `` "pending"``, `` "success"``, `` "error"`` .
379
+ - ``operation``: For a list of all operation names, refer to the
371
380
:realm-react-sdk:`API documentation <enums/AuthOperationName.html>`.
372
- - ``pending``. Can be ``true`` or ``false``.
373
- - ``success``. Can be ``true`` or ``false``.
374
- - ``error``. Error-based object or undefined.
381
+ - ``pending``: Can be ``true`` or ``false``.
382
+ - ``success``: Can be ``true`` or ``false``.
383
+ - ``error``: Error-based object or undefined.
375
384
376
385
Authentication Methods
377
386
++++++++++++++++++++++
@@ -381,12 +390,13 @@ The authentication method specifies how you want users to login to your app. ``u
381
390
.. list-table::
382
391
:header-rows: 1
383
392
:stub-columns: 1
393
+ :widths: 15 20 65
384
394
385
395
* - Operation
386
396
- Parameter
387
397
- Example
388
398
389
- * - `` logIn(credentials)``
399
+ * - logIn
390
400
- ``credentials``: An Atlas credential supplied by any supported Atlas authentication.
391
401
- Logs in a user with any authentication mechanism supported by Atlas. If called when a
392
402
user is logged in, the current user switches to the new user. Usually, it's better to use
@@ -411,7 +421,7 @@ The authentication method specifies how you want users to login to your app. ``u
411
421
}
412
422
//...
413
423
414
- * - `` logInWithAnonymous``
424
+ * - logInWithAnonymous
415
425
- None
416
426
- Log in with the anonymous authentication provider.
417
427
@@ -422,7 +432,7 @@ The authentication method specifies how you want users to login to your app. ``u
422
432
logInWithAnonymous();
423
433
};
424
434
425
- * - `` logInWithApiKey(key)``
435
+ * - logInWithApiKey
426
436
- ``key``: A string that is linked to an App Services user.
427
437
- Log in with an API key.
428
438
@@ -434,7 +444,7 @@ The authentication method specifies how you want users to login to your app. ``u
434
444
logInWithApiKey(key);
435
445
};
436
446
437
- * - `` logInWithEmailPassword(credentials)``
447
+ * - logInWithEmailPassword
438
448
- ``credentials``: An object with ``email`` and ``password`` fields.
439
449
- Log in with Email/Password.
440
450
@@ -448,7 +458,7 @@ The authentication method specifies how you want users to login to your app. ``u
448
458
logInWithEmailPassword({email, password});
449
459
};
450
460
451
- * - `` logInWithJWT(credentials)``
461
+ * - logInWithJWT
452
462
- ``credentials``: A string representation of a user's JWT.
453
463
- Log in with a JSON Web Token (JWT).
454
464
@@ -461,7 +471,7 @@ The authentication method specifies how you want users to login to your app. ``u
461
471
logInWithJWT(token);
462
472
};
463
473
464
- * - `` logInWithGoogle(credentials)``
474
+ * - logInWithGoogle
465
475
- ``credentials``: An object with an ``idToken`` or ``authCode`` field that
466
476
should contain the string token you get from Google Identity Services.
467
477
- Log in with Google.
@@ -475,7 +485,7 @@ The authentication method specifies how you want users to login to your app. ``u
475
485
logInWithGoogle({idToken: token});
476
486
};
477
487
478
- * - `` logInWithApple(idToken)``
488
+ * - logInWithApple
479
489
- ``idToken``: A string you get from the Apple SDK.
480
490
- Log in with Apple.
481
491
@@ -488,7 +498,7 @@ The authentication method specifies how you want users to login to your app. ``u
488
498
logInWithApple(token);
489
499
};
490
500
491
- * - `` logInWithFacebook(accessToken)``
501
+ * - logInWithFacebook
492
502
- ``accessToken``: A string you get from the Facebook SDK.
493
503
- Log in with Facebook.
494
504
@@ -501,7 +511,7 @@ The authentication method specifies how you want users to login to your app. ``u
501
511
logInWithFacebook(token);
502
512
};
503
513
504
- * - `` logInWithFunction(payload)``
514
+ * - logInWithFunction
505
515
- ``payload``: An object that contains user information you want to pass to
506
516
the App Services function that processes log in requests.
507
517
- Log in with a custom function.
@@ -515,7 +525,7 @@ The authentication method specifies how you want users to login to your app. ``u
515
525
logInWithFunction(customPayload);
516
526
};
517
527
518
- * - `` logOut()``
528
+ * - logOut
519
529
- None
520
530
- Logs out the current user.
521
531
@@ -547,12 +557,12 @@ operation.
547
557
548
558
*Enum values*
549
559
550
- - ``state``. Can be "not-started", "pending", "success", "error".
551
- - ``operation``. For a list of all operation names, refer to the
560
+ - ``state``: Can be `` "not-started"``, `` "pending"``, `` "success"``, `` "error"`` .
561
+ - ``operation``: For a list of all operation names, refer to the
552
562
:realm-react-sdk:`API documentation <enums/AuthOperationName.html>`.
553
- - ``pending``. Can be ``true`` or ``false``.
554
- - ``success``. Can be ``true`` or ``false``.
555
- - ``error``. Error-based object or undefined.
563
+ - ``pending``: Can be ``true`` or ``false``.
564
+ - ``success``: Can be ``true`` or ``false``.
565
+ - ``error``: Error-based object or undefined.
556
566
557
567
Authentication Operations
558
568
+++++++++++++++++++++++++
@@ -562,12 +572,13 @@ Authentication Operations
562
572
.. list-table::
563
573
:header-rows: 1
564
574
:stub-columns: 1
575
+ :widths: 15 20 65
565
576
566
577
* - Operation
567
578
- Parameter
568
579
- Example
569
580
570
- * - `` logIn(credentials)``
581
+ * - logIn
571
582
- ``credentials``: An object that contains ``email`` and ``password`` properties.
572
583
- Logs a user in using an email and password. You could also call
573
584
``logIn(Realm.Credentials.emailPassword(email, password))``. Returns a
@@ -597,7 +608,7 @@ Authentication Operations
597
608
}
598
609
//...
599
610
600
- * - `` logOut()``
611
+ * - logOut
601
612
- None
602
613
- Logs out the current user.
603
614
@@ -608,7 +619,7 @@ Authentication Operations
608
619
logOut();
609
620
}
610
621
611
- * - `` register(args)``
622
+ * - register
612
623
- ``args``: An object that contains ``email`` and ``password`` properties.
613
624
- Registers a new user. Requires a user email and password.
614
625
@@ -623,7 +634,7 @@ Authentication Operations
623
634
register({email, password});
624
635
};
625
636
626
- * - `` confirm(args)``
637
+ * - confirm
627
638
- ``args``: An object that contains ``token`` and ``tokenId`` properties.
628
639
- Confirms a user account. Requires a ``token`` and ``tokenId``.
629
640
@@ -635,7 +646,7 @@ Authentication Operations
635
646
confirm({token, tokenId});
636
647
};
637
648
638
- * - `` resendConfirmationEmail(args)``
649
+ * - resendConfirmationEmail
639
650
- ``args``: An object that contains an ``email`` property.
640
651
- Resends a confirmation email.
641
652
@@ -648,7 +659,7 @@ Authentication Operations
648
659
resendConfirmationEmail({email});
649
660
};
650
661
651
- * - `` retryCustomConfirmation(args)``
662
+ * - retryCustomConfirmation
652
663
- ``args``: An object that contains an ``email`` property.
653
664
- Retries confirmation with a custom function.
654
665
@@ -661,7 +672,7 @@ Authentication Operations
661
672
retryCustomConfirmation({email});
662
673
};
663
674
664
- * - `` sendResetPasswordEmail(args)``
675
+ * - sendResetPasswordEmail
665
676
- ``args``: An object that contains an ``email`` property.
666
677
- Sends a password reset email.
667
678
@@ -674,7 +685,7 @@ Authentication Operations
674
685
sendResetPasswordEmail({email});
675
686
};
676
687
677
- * - `` resetPassword(args)``
688
+ * - resetPassword
678
689
- ``args``: An object that contains ``token``, ``tokenId``, and ``password``
679
690
properties.
680
691
- Resets a user's password.
@@ -688,7 +699,7 @@ Authentication Operations
688
699
resetPassword({token, tokenId, password});
689
700
};
690
701
691
- * - `` callResetPasswordFunction(args, restArgs)``
702
+ * - callResetPasswordFunction
692
703
- ``args``: An object that contains ``email`` and ``password`` properties.
693
704
694
705
``restArgs``: Additional arguments that you need to pass to your custom
@@ -717,16 +728,6 @@ Create Context with createRealmContext()
717
728
718
729
createRealmContext(realmConfig?): RealmContext
719
730
720
- *Parameters*
721
-
722
- - ``realmConfig?: Realm.Configuration`` All properties of :realm-react-sdk:`BaseConfiguration
723
- <types/Realm.BaseConfiguration.html>` can be used.
724
-
725
- *Returns*
726
-
727
- - ``RealmContext`` An object containing a ``RealmProvider`` component, and the ``useRealm``,
728
- ``useQuery`` and ``useObject`` Hooks.
729
-
730
731
Most of the time, you will only use ``createRealmContext()`` if you need to
731
732
configure more than one database. Otherwise, you should import ``RealmProvider``
732
733
and its associated Hooks directly from ``@realm/react``.
@@ -746,4 +747,14 @@ provider and use its associated Hooks the same way you would with the ``RealmPro
746
747
imported from the ``@realm/react`` library. You should namespace providers
747
748
to avoid confusion about which provider and Hooks you're working with.
748
749
750
+ *Parameters*
751
+
752
+ - ``realmConfig?: Realm.Configuration`` All properties of :realm-react-sdk:`BaseConfiguration
753
+ <types/Realm.BaseConfiguration.html>` can be used.
754
+
755
+ *Returns*
756
+
757
+ - ``RealmContext`` An object containing a ``RealmProvider`` component, and the ``useRealm``,
758
+ ``useQuery`` and ``useObject`` Hooks.
759
+
749
760
For a detailed guide, refer to :ref:`Expose More Than One Database <sdks-expose-more-than-one-database>`.
0 commit comments