Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[outdated] Consolidation Providers & Hooks #3339

Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
auth email password methods
osharaf-mdb committed Jul 31, 2024
commit a90048bb4c19c99e23250381587529ed05201013
324 changes: 109 additions & 215 deletions source/frameworks/react/providers-hooks.txt
Original file line number Diff line number Diff line change
@@ -361,7 +361,7 @@ use in any wrapped component.

.. glossary::

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

``useEmailPasswordAuth`` returns ``result`` and an authentication method you specify, as
shown below.

result
``````

.. code:: typescript
:copyable: false
:caption: Type signature
@@ -516,270 +522,158 @@ use in any wrapped component.
*Enum values*

- ``state``. Can be "not-started", "pending", "success", "error".
- ``operation``. For a list of all operation names, refer to the
:realm-react-sdk:`API documentation <enums/AuthOperationName.html>`.
- ``pending``. Can be ``true`` or ``false``.
- ``success``. Can be ``true`` or ``false``.
- ``error``. Error-based object or undefined.

logIn(credentials)
``````````````````

.. code:: typescript
:copyable: false
:caption: Type signature

logIn(credentials: { email: string; password: string }): void;

*Parameters*

- ``credentials``. An object that contains ``email`` and ``password`` properties.

*Example*

Logs a user in using an email and password. You could also call
``logIn(Realm.Credentials.emailPassword(email, password))``. Returns a
``Realm.User`` instance of the logged-in user.

.. code:: typescript

const {logIn, result} = useEmailPasswordAuth();

const [email, setEmail] = useState('');
const [password, setPassword] = useState('');

const performLogin = () => {
logIn({email, password});
};

if(result.pending) {
return (<LoadingSpinner/>)
}

if(result.error) {
return (<ErrorComponent/>)
}

if(result.success) {
return (<SuccessComponent/>)
}
//...

logOut()
````````

.. code:: typescript
:copyable: false
:caption: Type signature

logOut(): void;

*Example*

Logs out the current user.

.. code:: typescript

const {logOut, result} = useEmailPasswordAuth();
const performLogout = () => {
logOut();
}

register(args)
``````````````

.. code:: typescript
:copyable: false
:caption: Type signature

register(args: { email: string; password: string }): void;

*Parameters*

- ``args``. An object that contains ``email`` and ``password`` properties.

*Example*

Registers a new user. Requires a user email and password.

.. code:: typescript

const {register, result} = useEmailPasswordAuth();

const [email, setEmail] = useState('');
const [password, setPassword] = useState('');

const performRegister = () => {
register({email, password});
};

confirm(args)
`````````````

.. code:: typescript
:copyable: false
:caption: Type signature

confirm(args: { token: string; tokenId: string }): void;

*Parameters*

- ``args``. An object that contains ``token`` and ``tokenId`` properties.

*Example*

Confirms a user account. Requires a ``token`` and ``tokenId``.

.. code:: typescript

const {confirm, result} = useEmailPasswordAuth();

const performConfirmation = () => {
confirm({token, tokenId});
};

resendConfirmationEmail(args)
`````````````````````````````

.. code:: typescript
:copyable: false
:caption: Type signature
- ``operation``. For a list of all operation names, refer to the
:realm-react-sdk:`API documentation <enums/AuthOperationName.html>`.

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

*Parameters*
- ``success``. Can be ``true`` or ``false``.

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

*Example*
Authentication Methods
`````````````````

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

.. code:: typescript
.. glossary::

const {resendConfirmationEmail, result} = useEmailPasswordAuth();
const [email, setEmail] = useState('');
logIn(credentials)
.. code:: typescript
:copyable: false
:caption: Type signature

const performResendConfirmationEmail = () => {
resendConfirmationEmail({email});
};
logIn(credentials: { email: string; password: string }): void;

retryCustomConfirmation(args)
`````````````````````````````
*Parameters*

.. code:: typescript
:copyable: false
:caption: Type signature
- ``credentials``. An object that contains ``email`` and ``password`` properties.

retryCustomConfirmation(args: { email: string }): void;
*Example*

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

- ``args``. An object that contains an ``email`` property.
.. code:: typescript

*Example*
const {logIn, result} = useEmailPasswordAuth();

Retries confirmation with a custom function.
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');

.. code:: typescript
const performLogin = () => {
logIn({email, password});
};

const {retryCustomConfirmation, result} = useEmailPasswordAuth();
const [email, setEmail] = useState('');
if(result.pending) {
return (<LoadingSpinner/>)
}

const performRetryCustomConfirmation = () => {
retryCustomConfirmation({email});
};
if(result.error) {
return (<ErrorComponent/>)
}

sendResetPasswordEmail(args)
`````````````````````````````
if(result.success) {
return (<SuccessComponent/>)
}
//...

.. code:: typescript
:copyable: false
:caption: Type signature
logOut()
.. code:: typescript
:copyable: false
:caption: Type signature

sendResetPasswordEmail(args: { email: string }): void;
logOut(): void;

*Parameters*
register(args)
.. code:: typescript
:copyable: false
:caption: Type signature

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

*Example*
*Parameters*

Sends a password reset email.
- ``args``. An object that contains ``email`` and ``password`` properties.

.. code:: typescript
confirm(args)
.. code:: typescript
:copyable: false
:caption: Type signature

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

const performSendResetPasswordEmail = () => {
sendResetPasswordEmail({email});
};
*Parameters*

resetPassword(args)
```````````````````
- ``args``. An object that contains ``token`` and ``tokenId`` properties.

.. code:: typescript
:copyable: false
:caption: Type signature
resendConfirmationEmail(args)
.. code:: typescript
:copyable: false
:caption: Type signature

resetPassword(args: { token: string; tokenId: string; password: string }): void;
resendConfirmationEmail(args: { email: string }): void;

*Parameters*
*Parameters*

- ``args``. An object that contains ``token``, ``tokenId``, and ``password``
properties.
- ``args``. An object that contains an ``email`` property.

*Example*
retryCustomConfirmation(args)
.. code:: typescript
:copyable: false
:caption: Type signature

Resets a user's password.
retryCustomConfirmation(args: { email: string }): void;

.. code:: typescript
*Parameters*

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

const performResetPassword = () => {
resetPassword({token, tokenId, password});
};
sendResetPasswordEmail(args)
.. code:: typescript
:copyable: false
:caption: Type signature

callResetPasswordFunction(args, restArgs)
`````````````````````````````````````````
sendResetPasswordEmail(args: { email: string }): void;

.. code:: typescript
:copyable: false
:caption: Type signature
*Parameters*

callResetPasswordFunction<Args extends unknown[] = []>(
args: {
email: string;
password: string;
},
...restArgs: Args
): void;
- ``args``. An object that contains an ``email`` property.

*Parameters*
resetPassword(args)
.. code:: typescript
:copyable: false
:caption: Type signature

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

*Example*
*Parameters*

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

.. code:: typescript
callResetPasswordFunction(args, restArgs)
.. code:: typescript
:copyable: false
:caption: Type signature

const {callResetPasswordFunction, result} = useEmailPasswordAuth();
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
callResetPasswordFunction<Args extends unknown[] = []>(
args: {
email: string;
password: string;
},
...restArgs: Args
): void;

const performResetPassword = () => {
callResetPasswordFunction({email, password}, "extraArg1", "extraArg2");
};
*Parameters*

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

useApp()
~~~~~~~~