@@ -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,30 @@ 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.
123
+
124
+ - For more information, refer to the :js-sdk:`Realm App API documentation <classes/Realm.App-1.html>`.
125
+
126
+ - ``UserProvider``: Used to access the logged-in :ref:`user object <user-accounts>`.
115
127
116
- - ``UserProvider``: Used to access the logged-in :js-sdk:`user object <classes/Realm.User.html>`.
128
+ - For more information, refer to the :js-sdk:`Realm User API documentation <classes/Realm.User.html>`.
117
129
118
- - ``RealmProvider``: Used to work with the configured :js-sdk:`database <classes/Realm-1.html>`.
130
+ - ``RealmProvider``: Used to work with the configured database.
131
+
132
+ - For more information, refer to the :js-sdk:`Realm API documentation <classes/Realm-1.html>`.
119
133
120
134
The example below walks through configuring all three providers. If your app does not need a
121
135
certain provider, you can skip the steps and omit the code for that provider.
122
136
137
+ .. note:: Exposing more than one database using createRealmContext()
138
+
139
+ The example details how to configure and expose a single database using a ``RealmProvider``
140
+ imported directly from ``@realm/react``.
141
+ For information about using ``createRealmContext()`` to configure a database or exposing more
142
+ than one database, see :ref:`Create Context with createRealmContext()
143
+ <create_context_with_createrealmcontext>` below.
144
+
123
145
**To configure your providers:**
124
146
125
147
1. Import ``RealmProvider``, ``AppProvider``, and ``UserProvider`` from ``@realm/react``.
@@ -146,9 +168,10 @@ certain provider, you can skip the steps and omit the code for that provider.
146
168
147
169
c. Add other configuration object properties as props to ``RealmProvider`` as needed.
148
170
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.
171
+ 5. Nest you app components in the providers.
172
+ Once your providers have been configured, nest your app components within the
173
+ provider whose context it needs to access. Generally, you can nest your components within the
174
+ ``RealmProvider`` to ensure they have access to all three providers' contexts.
152
175
153
176
The rendering of each component is dependent on the successful
154
177
execution of its parent components' functionality. For example, if ``AppProvider`` cannot
@@ -159,14 +182,6 @@ You *must* nest the providers as shown below to ensure each has access to its re
159
182
.. literalinclude:: /examples/generated/react-native/ts/configure-realm-sync.test.snippet.configure-realm-sync-full.tsx
160
183
:language: javascript
161
184
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
185
Working with Providers using Hooks
171
186
----------------------------------
172
187
@@ -366,12 +381,12 @@ you the name of the current operation.
366
381
367
382
*Enum values*
368
383
369
- - ``state``. Can be "not-started", "pending", "success", "error".
370
- - ``operation``. For a list of all operation names, refer to the
384
+ - ``state``: Can be `` "not-started"``, `` "pending"``, `` "success"``, `` "error"`` .
385
+ - ``operation``: For a list of all operation names, refer to the
371
386
: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.
387
+ - ``pending``: Can be ``true`` or ``false``.
388
+ - ``success``: Can be ``true`` or ``false``.
389
+ - ``error``: Error-based object or undefined.
375
390
376
391
Authentication Methods
377
392
++++++++++++++++++++++
@@ -381,12 +396,13 @@ The authentication method specifies how you want users to login to your app. ``u
381
396
.. list-table::
382
397
:header-rows: 1
383
398
:stub-columns: 1
399
+ :widths: 15 20 65
384
400
385
401
* - Operation
386
402
- Parameter
387
403
- Example
388
404
389
- * - `` logIn(credentials)``
405
+ * - logIn
390
406
- ``credentials``: An Atlas credential supplied by any supported Atlas authentication.
391
407
- Logs in a user with any authentication mechanism supported by Atlas. If called when a
392
408
user is logged in, the current user switches to the new user. Usually, it's better to use
@@ -411,7 +427,7 @@ The authentication method specifies how you want users to login to your app. ``u
411
427
}
412
428
//...
413
429
414
- * - `` logInWithAnonymous``
430
+ * - logInWithAnonymous
415
431
- None
416
432
- Log in with the anonymous authentication provider.
417
433
@@ -422,7 +438,7 @@ The authentication method specifies how you want users to login to your app. ``u
422
438
logInWithAnonymous();
423
439
};
424
440
425
- * - `` logInWithApiKey(key)``
441
+ * - logInWithApiKey
426
442
- ``key``: A string that is linked to an App Services user.
427
443
- Log in with an API key.
428
444
@@ -434,7 +450,7 @@ The authentication method specifies how you want users to login to your app. ``u
434
450
logInWithApiKey(key);
435
451
};
436
452
437
- * - `` logInWithEmailPassword(credentials)``
453
+ * - logInWithEmailPassword
438
454
- ``credentials``: An object with ``email`` and ``password`` fields.
439
455
- Log in with Email/Password.
440
456
@@ -448,7 +464,7 @@ The authentication method specifies how you want users to login to your app. ``u
448
464
logInWithEmailPassword({email, password});
449
465
};
450
466
451
- * - `` logInWithJWT(credentials)``
467
+ * - logInWithJWT
452
468
- ``credentials``: A string representation of a user's JWT.
453
469
- Log in with a JSON Web Token (JWT).
454
470
@@ -461,7 +477,7 @@ The authentication method specifies how you want users to login to your app. ``u
461
477
logInWithJWT(token);
462
478
};
463
479
464
- * - `` logInWithGoogle(credentials)``
480
+ * - logInWithGoogle
465
481
- ``credentials``: An object with an ``idToken`` or ``authCode`` field that
466
482
should contain the string token you get from Google Identity Services.
467
483
- Log in with Google.
@@ -475,7 +491,7 @@ The authentication method specifies how you want users to login to your app. ``u
475
491
logInWithGoogle({idToken: token});
476
492
};
477
493
478
- * - `` logInWithApple(idToken)``
494
+ * - logInWithApple
479
495
- ``idToken``: A string you get from the Apple SDK.
480
496
- Log in with Apple.
481
497
@@ -488,7 +504,7 @@ The authentication method specifies how you want users to login to your app. ``u
488
504
logInWithApple(token);
489
505
};
490
506
491
- * - `` logInWithFacebook(accessToken)``
507
+ * - logInWithFacebook
492
508
- ``accessToken``: A string you get from the Facebook SDK.
493
509
- Log in with Facebook.
494
510
@@ -501,7 +517,7 @@ The authentication method specifies how you want users to login to your app. ``u
501
517
logInWithFacebook(token);
502
518
};
503
519
504
- * - `` logInWithFunction(payload)``
520
+ * - logInWithFunction
505
521
- ``payload``: An object that contains user information you want to pass to
506
522
the App Services function that processes log in requests.
507
523
- Log in with a custom function.
@@ -515,7 +531,7 @@ The authentication method specifies how you want users to login to your app. ``u
515
531
logInWithFunction(customPayload);
516
532
};
517
533
518
- * - `` logOut()``
534
+ * - logOut
519
535
- None
520
536
- Logs out the current user.
521
537
@@ -547,12 +563,12 @@ operation.
547
563
548
564
*Enum values*
549
565
550
- - ``state``. Can be "not-started", "pending", "success", "error".
551
- - ``operation``. For a list of all operation names, refer to the
566
+ - ``state``: Can be `` "not-started"``, `` "pending"``, `` "success"``, `` "error"`` .
567
+ - ``operation``: For a list of all operation names, refer to the
552
568
: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.
569
+ - ``pending``: Can be ``true`` or ``false``.
570
+ - ``success``: Can be ``true`` or ``false``.
571
+ - ``error``: Error-based object or undefined.
556
572
557
573
Authentication Operations
558
574
+++++++++++++++++++++++++
@@ -562,12 +578,13 @@ Authentication Operations
562
578
.. list-table::
563
579
:header-rows: 1
564
580
:stub-columns: 1
581
+ :widths: 15 20 65
565
582
566
583
* - Operation
567
584
- Parameter
568
585
- Example
569
586
570
- * - `` logIn(credentials)``
587
+ * - logIn
571
588
- ``credentials``: An object that contains ``email`` and ``password`` properties.
572
589
- Logs a user in using an email and password. You could also call
573
590
``logIn(Realm.Credentials.emailPassword(email, password))``. Returns a
@@ -597,7 +614,7 @@ Authentication Operations
597
614
}
598
615
//...
599
616
600
- * - `` logOut()``
617
+ * - logOut
601
618
- None
602
619
- Logs out the current user.
603
620
@@ -608,7 +625,7 @@ Authentication Operations
608
625
logOut();
609
626
}
610
627
611
- * - `` register(args)``
628
+ * - register
612
629
- ``args``: An object that contains ``email`` and ``password`` properties.
613
630
- Registers a new user. Requires a user email and password.
614
631
@@ -623,7 +640,7 @@ Authentication Operations
623
640
register({email, password});
624
641
};
625
642
626
- * - `` confirm(args)``
643
+ * - confirm
627
644
- ``args``: An object that contains ``token`` and ``tokenId`` properties.
628
645
- Confirms a user account. Requires a ``token`` and ``tokenId``.
629
646
@@ -635,7 +652,7 @@ Authentication Operations
635
652
confirm({token, tokenId});
636
653
};
637
654
638
- * - `` resendConfirmationEmail(args)``
655
+ * - resendConfirmationEmail
639
656
- ``args``: An object that contains an ``email`` property.
640
657
- Resends a confirmation email.
641
658
@@ -648,7 +665,7 @@ Authentication Operations
648
665
resendConfirmationEmail({email});
649
666
};
650
667
651
- * - `` retryCustomConfirmation(args)``
668
+ * - retryCustomConfirmation
652
669
- ``args``: An object that contains an ``email`` property.
653
670
- Retries confirmation with a custom function.
654
671
@@ -661,7 +678,7 @@ Authentication Operations
661
678
retryCustomConfirmation({email});
662
679
};
663
680
664
- * - `` sendResetPasswordEmail(args)``
681
+ * - sendResetPasswordEmail
665
682
- ``args``: An object that contains an ``email`` property.
666
683
- Sends a password reset email.
667
684
@@ -674,7 +691,7 @@ Authentication Operations
674
691
sendResetPasswordEmail({email});
675
692
};
676
693
677
- * - `` resetPassword(args)``
694
+ * - resetPassword
678
695
- ``args``: An object that contains ``token``, ``tokenId``, and ``password``
679
696
properties.
680
697
- Resets a user's password.
@@ -688,7 +705,7 @@ Authentication Operations
688
705
resetPassword({token, tokenId, password});
689
706
};
690
707
691
- * - `` callResetPasswordFunction(args, restArgs)``
708
+ * - callResetPasswordFunction
692
709
- ``args``: An object that contains ``email`` and ``password`` properties.
693
710
694
711
``restArgs``: Additional arguments that you need to pass to your custom
@@ -717,16 +734,6 @@ Create Context with createRealmContext()
717
734
718
735
createRealmContext(realmConfig?): RealmContext
719
736
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
737
Most of the time, you will only use ``createRealmContext()`` if you need to
731
738
configure more than one database. Otherwise, you should import ``RealmProvider``
732
739
and its associated Hooks directly from ``@realm/react``.
@@ -746,4 +753,14 @@ provider and use its associated Hooks the same way you would with the ``RealmPro
746
753
imported from the ``@realm/react`` library. You should namespace providers
747
754
to avoid confusion about which provider and Hooks you're working with.
748
755
756
+ *Parameters*
757
+
758
+ - ``realmConfig?: Realm.Configuration`` All properties of :realm-react-sdk:`BaseConfiguration
759
+ <types/Realm.BaseConfiguration.html>` can be used.
760
+
761
+ *Returns*
762
+
763
+ - ``RealmContext`` An object containing a ``RealmProvider`` component, and the ``useRealm``,
764
+ ``useQuery`` and ``useObject`` Hooks.
765
+
749
766
For a detailed guide, refer to :ref:`Expose More Than One Database <sdks-expose-more-than-one-database>`.
0 commit comments