Skip to content

Commit a90048b

Browse files
committed
auth email password methods
1 parent d3a2585 commit a90048b

File tree

1 file changed

+109
-215
lines changed

1 file changed

+109
-215
lines changed

source/frameworks/react/providers-hooks.txt

Lines changed: 109 additions & 215 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ use in any wrapped component.
361361

362362
.. glossary::
363363

364-
**logIn(credentials)**
364+
logIn(credentials)
365365
.. code:: typescript
366366
:copyable: false
367367
:caption: Type signature
@@ -504,6 +504,12 @@ use in any wrapped component.
504504
useEmailPasswordAuth()
505505
~~~~~~~~~~~~~~~~~~~~~~
506506

507+
``useEmailPasswordAuth`` returns ``result`` and an authentication method you specify, as
508+
shown below.
509+
510+
result
511+
``````
512+
507513
.. code:: typescript
508514
:copyable: false
509515
:caption: Type signature
@@ -516,270 +522,158 @@ use in any wrapped component.
516522
*Enum values*
517523

518524
- ``state``. Can be "not-started", "pending", "success", "error".
519-
- ``operation``. For a list of all operation names, refer to the
520-
:realm-react-sdk:`API documentation <enums/AuthOperationName.html>`.
521-
- ``pending``. Can be ``true`` or ``false``.
522-
- ``success``. Can be ``true`` or ``false``.
523-
- ``error``. Error-based object or undefined.
524-
525-
logIn(credentials)
526-
``````````````````
527-
528-
.. code:: typescript
529-
:copyable: false
530-
:caption: Type signature
531-
532-
logIn(credentials: { email: string; password: string }): void;
533-
534-
*Parameters*
535-
536-
- ``credentials``. An object that contains ``email`` and ``password`` properties.
537-
538-
*Example*
539-
540-
Logs a user in using an email and password. You could also call
541-
``logIn(Realm.Credentials.emailPassword(email, password))``. Returns a
542-
``Realm.User`` instance of the logged-in user.
543-
544-
.. code:: typescript
545-
546-
const {logIn, result} = useEmailPasswordAuth();
547-
548-
const [email, setEmail] = useState('');
549-
const [password, setPassword] = useState('');
550-
551-
const performLogin = () => {
552-
logIn({email, password});
553-
};
554-
555-
if(result.pending) {
556-
return (<LoadingSpinner/>)
557-
}
558-
559-
if(result.error) {
560-
return (<ErrorComponent/>)
561-
}
562-
563-
if(result.success) {
564-
return (<SuccessComponent/>)
565-
}
566-
//...
567-
568-
logOut()
569-
````````
570-
571-
.. code:: typescript
572-
:copyable: false
573-
:caption: Type signature
574-
575-
logOut(): void;
576-
577-
*Example*
578-
579-
Logs out the current user.
580-
581-
.. code:: typescript
582-
583-
const {logOut, result} = useEmailPasswordAuth();
584-
const performLogout = () => {
585-
logOut();
586-
}
587525

588-
register(args)
589-
``````````````
590-
591-
.. code:: typescript
592-
:copyable: false
593-
:caption: Type signature
594-
595-
register(args: { email: string; password: string }): void;
596-
597-
*Parameters*
598-
599-
- ``args``. An object that contains ``email`` and ``password`` properties.
600-
601-
*Example*
602-
603-
Registers a new user. Requires a user email and password.
604-
605-
.. code:: typescript
606-
607-
const {register, result} = useEmailPasswordAuth();
608-
609-
const [email, setEmail] = useState('');
610-
const [password, setPassword] = useState('');
611-
612-
const performRegister = () => {
613-
register({email, password});
614-
};
615-
616-
confirm(args)
617-
`````````````
618-
619-
.. code:: typescript
620-
:copyable: false
621-
:caption: Type signature
622-
623-
confirm(args: { token: string; tokenId: string }): void;
624-
625-
*Parameters*
626-
627-
- ``args``. An object that contains ``token`` and ``tokenId`` properties.
628-
629-
*Example*
630-
631-
Confirms a user account. Requires a ``token`` and ``tokenId``.
632-
633-
.. code:: typescript
634-
635-
const {confirm, result} = useEmailPasswordAuth();
636-
637-
const performConfirmation = () => {
638-
confirm({token, tokenId});
639-
};
640-
641-
resendConfirmationEmail(args)
642-
`````````````````````````````
643-
644-
.. code:: typescript
645-
:copyable: false
646-
:caption: Type signature
526+
- ``operation``. For a list of all operation names, refer to the
527+
:realm-react-sdk:`API documentation <enums/AuthOperationName.html>`.
647528

648-
resendConfirmationEmail(args: { email: string }): void;
529+
- ``pending``. Can be ``true`` or ``false``.
649530

650-
*Parameters*
531+
- ``success``. Can be ``true`` or ``false``.
651532

652-
- ``args``. An object that contains an ``email`` property.
533+
- ``error``. Error-based object or undefined.
653534

654-
*Example*
535+
Authentication Methods
536+
`````````````````
655537

656-
Resends a confirmation email.
538+
Below is a list of authentication methods and their Type signatures. An example of using
539+
an authentication method is provided for ``logIn(credentials)``. You use the other authentication
540+
methods in the same way.
657541

658-
.. code:: typescript
542+
.. glossary::
659543

660-
const {resendConfirmationEmail, result} = useEmailPasswordAuth();
661-
const [email, setEmail] = useState('');
544+
logIn(credentials)
545+
.. code:: typescript
546+
:copyable: false
547+
:caption: Type signature
662548

663-
const performResendConfirmationEmail = () => {
664-
resendConfirmationEmail({email});
665-
};
549+
logIn(credentials: { email: string; password: string }): void;
666550

667-
retryCustomConfirmation(args)
668-
`````````````````````````````
551+
*Parameters*
669552

670-
.. code:: typescript
671-
:copyable: false
672-
:caption: Type signature
553+
- ``credentials``. An object that contains ``email`` and ``password`` properties.
673554

674-
retryCustomConfirmation(args: { email: string }): void;
555+
*Example*
675556

676-
*Parameters*
557+
Logs a user in using an email and password. You could also call
558+
``logIn(Realm.Credentials.emailPassword(email, password))``. Returns a
559+
``Realm.User`` instance of the logged-in user.
677560

678-
- ``args``. An object that contains an ``email`` property.
561+
.. code:: typescript
679562

680-
*Example*
563+
const {logIn, result} = useEmailPasswordAuth();
681564

682-
Retries confirmation with a custom function.
565+
const [email, setEmail] = useState('');
566+
const [password, setPassword] = useState('');
683567

684-
.. code:: typescript
568+
const performLogin = () => {
569+
logIn({email, password});
570+
};
685571

686-
const {retryCustomConfirmation, result} = useEmailPasswordAuth();
687-
const [email, setEmail] = useState('');
572+
if(result.pending) {
573+
return (<LoadingSpinner/>)
574+
}
688575

689-
const performRetryCustomConfirmation = () => {
690-
retryCustomConfirmation({email});
691-
};
576+
if(result.error) {
577+
return (<ErrorComponent/>)
578+
}
692579

693-
sendResetPasswordEmail(args)
694-
`````````````````````````````
580+
if(result.success) {
581+
return (<SuccessComponent/>)
582+
}
583+
//...
695584

696-
.. code:: typescript
697-
:copyable: false
698-
:caption: Type signature
585+
logOut()
586+
.. code:: typescript
587+
:copyable: false
588+
:caption: Type signature
699589

700-
sendResetPasswordEmail(args: { email: string }): void;
590+
logOut(): void;
701591

702-
*Parameters*
592+
register(args)
593+
.. code:: typescript
594+
:copyable: false
595+
:caption: Type signature
703596

704-
- ``args``. An object that contains an ``email`` property.
597+
register(args: { email: string; password: string }): void;
705598

706-
*Example*
599+
*Parameters*
707600

708-
Sends a password reset email.
601+
- ``args``. An object that contains ``email`` and ``password`` properties.
709602

710-
.. code:: typescript
603+
confirm(args)
604+
.. code:: typescript
605+
:copyable: false
606+
:caption: Type signature
711607

712-
const {sendResetPasswordEmail, result} = useEmailPasswordAuth();
713-
const [email, setEmail] = useState('');
608+
confirm(args: { token: string; tokenId: string }): void;
714609

715-
const performSendResetPasswordEmail = () => {
716-
sendResetPasswordEmail({email});
717-
};
610+
*Parameters*
718611

719-
resetPassword(args)
720-
```````````````````
612+
- ``args``. An object that contains ``token`` and ``tokenId`` properties.
721613

722-
.. code:: typescript
723-
:copyable: false
724-
:caption: Type signature
614+
resendConfirmationEmail(args)
615+
.. code:: typescript
616+
:copyable: false
617+
:caption: Type signature
725618

726-
resetPassword(args: { token: string; tokenId: string; password: string }): void;
619+
resendConfirmationEmail(args: { email: string }): void;
727620

728-
*Parameters*
621+
*Parameters*
729622

730-
- ``args``. An object that contains ``token``, ``tokenId``, and ``password``
731-
properties.
623+
- ``args``. An object that contains an ``email`` property.
732624

733-
*Example*
625+
retryCustomConfirmation(args)
626+
.. code:: typescript
627+
:copyable: false
628+
:caption: Type signature
734629

735-
Resets a user's password.
630+
retryCustomConfirmation(args: { email: string }): void;
736631

737-
.. code:: typescript
632+
*Parameters*
738633

739-
const {resetPassword, result} = useEmailPasswordAuth();
740-
const [password, setPassword] = useState('');
634+
- ``args``. An object that contains an ``email`` property.
741635

742-
const performResetPassword = () => {
743-
resetPassword({token, tokenId, password});
744-
};
636+
sendResetPasswordEmail(args)
637+
.. code:: typescript
638+
:copyable: false
639+
:caption: Type signature
745640

746-
callResetPasswordFunction(args, restArgs)
747-
`````````````````````````````````````````
641+
sendResetPasswordEmail(args: { email: string }): void;
748642

749-
.. code:: typescript
750-
:copyable: false
751-
:caption: Type signature
643+
*Parameters*
752644

753-
callResetPasswordFunction<Args extends unknown[] = []>(
754-
args: {
755-
email: string;
756-
password: string;
757-
},
758-
...restArgs: Args
759-
): void;
645+
- ``args``. An object that contains an ``email`` property.
760646

761-
*Parameters*
647+
resetPassword(args)
648+
.. code:: typescript
649+
:copyable: false
650+
:caption: Type signature
762651

763-
- ``args``. An object that contains ``email`` and ``password`` properties.
764-
- ``restArgs``. Additional arguments that you need to pass to your custom
765-
reset password function.
652+
resetPassword(args: { token: string; tokenId: string; password: string }): void;
766653

767-
*Example*
654+
*Parameters*
768655

769-
Calls your App Services backend password reset function. Can pass arguments to
770-
the function as needed.
656+
- ``args``. An object that contains ``token``, ``tokenId``, and ``password``
657+
properties.
771658

772-
.. code:: typescript
659+
callResetPasswordFunction(args, restArgs)
660+
.. code:: typescript
661+
:copyable: false
662+
:caption: Type signature
773663

774-
const {callResetPasswordFunction, result} = useEmailPasswordAuth();
775-
const [email, setEmail] = useState('');
776-
const [password, setPassword] = useState('');
664+
callResetPasswordFunction<Args extends unknown[] = []>(
665+
args: {
666+
email: string;
667+
password: string;
668+
},
669+
...restArgs: Args
670+
): void;
777671

778-
const performResetPassword = () => {
779-
callResetPasswordFunction({email, password}, "extraArg1", "extraArg2");
780-
};
672+
*Parameters*
781673

782-
.. _react-native-use-app-hook:
674+
- ``args``. An object that contains ``email`` and ``password`` properties.
675+
- ``restArgs``. Additional arguments that you need to pass to your custom
676+
reset password function.
783677

784678
useApp()
785679
~~~~~~~~

0 commit comments

Comments
 (0)