-
Notifications
You must be signed in to change notification settings - Fork 88
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
(DOCSP-33534) Add authentication hooks to React Native docs #3037
Conversation
Readability for Commit Hash: 7aa2f64 You can see any previous Readability scores (if they exist) by looking Readability scores for changed documents:
For Grade Level, aim for 8 or below. For Reading Ease scores, aim for 60 or above:
For help improving readability, try Hemingway App. |
- Make LinkCredentials more idiomatic
- Add password reset example and test
- Change bluhawk script input directory - Test hook reference table
- Generate new snippets
- Update authenticate users page - Update link users page
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work here, but I have some requests that should be addressed before this goes live.
#. In the component passed to the ``UserProvider.fallback`` prop, authenticate a | ||
user with the ``useEmailPasswordAuth()`` hook. | ||
This example uses email/password authentication, but you could use any of the | ||
``useAuth`` methods. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following example is not showing usage of the useEmailPasswordAuth
hook.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for noticing! I meant to alter this step and forgot to.
#. Call ``logInWithAnonymous()`` without any arguments. | ||
#. Handle the ``result``. | ||
|
||
.. include:: /examples/generated/react-native/v12/LoginWithAnonymous.snippet.login-anonymous.tsx.rst |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For these login examples, I think it may be worthwhile to wrap them in a functional component, just to make sure it's clear this is happening within a react component (should be obvious, but you never know).
|
||
.. include:: /examples/generated/react-native/v12/LoginWithEmail.snippet.email-password-login.tsx.rst | ||
|
||
.. _react-native-api-key-login: | ||
.. _react-native-login-api-key: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are hooks available for the following login strategies. Should we also show this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will! But this PR kept growing, so I wanted to break things up a bit. I created a small Jira epic to track the rest of the work: https://jira.mongodb.org/browse/DOCSP-27838
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Part of why this is so much work is that we're currently pulling examples from the Node.js test suite. And those examples are old and weren't well put together to begin with. So, gotta write new components.
|
||
.. _react-native-auth-hook: | ||
|
||
useAuth Hook |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really digging this table. Great reference
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do, however, think we should have an explanation about the "operation enum". Since nothing is awaitable, it's necessary to use the operation to determine which auth method is currently being processed.
Also it may be good to show the possible string
values for operation
, just in case someone has the gall to use plain JS instead of TypeScript.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great points about the enum. I'll update!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 on the table!
|
||
.. tabs-realm-languages:: | ||
.. include:: /examples/generated/react-native/v12/RealmWrapper.snippet.configure-user-provider.tsx.rst |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above for useAuth
. Perhaps if all the auth examples were wrapped in a Login
component to show that this is what is being rendered in the fallback. We could simply say, the Login
fallback examples are listed further down the document.
#. Pass the user's email and password to ``register()`` as an object. | ||
#. Confirm the user's email address. | ||
|
||
.. include:: /examples/generated/react-native/v12/LoginWithEmail.snippet.email-password-register.tsx.rst |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also get the result
in this example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since register
is not yet "awaitable", perhaps showing this flow would be helpful:
https://github.com/realm/realm-js/blob/main/examples/rn-todo-list/frontend/app/screens/LoginScreen.tsx#L50-L54
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. Good catch!
Calling the function in this example performs the entire password reset process. | ||
.. _react-native-email-pass-hook: | ||
|
||
useEmailPasswordAuth Hook |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
result
should also be added here.
.. step:: Create UI and Link Identities | ||
|
||
The following example renders the user ID for each identity associated | ||
with the app's current user. Initially, only the anonymou user |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with the app's current user. Initially, only the anonymou user | |
with the app's current user. Initially, only the anonymous user |
identity renders, but you can create an email/password identity and | ||
link it to the anonymous user. | ||
|
||
.. include:: /examples/generated/react-native/v12/LinkIdentities.snippet.user-identities.tsx.rst |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Upon reading this example, it occurred to me that we should probably have a linkCredentials
method returned from useAuth
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be helpful, for sure!
- Add user auth errors section - Regenerate updated snippets
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overall LGTM -- a few typos and non-blocking suggestions
|
||
.. literalinclude:: /examples/generated/node/authenticate.snippet.email-password-login.js | ||
:language: javascript | ||
#. Destructure ``logIn`` and ``result`` from the ``useEmailPasswordAuth`` hook. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know you mention it at the top of the page, but do we want to link out to the useEmailPasswordAuth
hook table here too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been trying to avoid links in procedure steps. Probably makes sense to include a mention of useEmailPasswordAuth
in the intro and link to it. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that makes sense! 👍
|
||
.. _react-native-auth-hook: | ||
|
||
useAuth Hook |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 on the table!
#. Handle ``result``. If the authentication operation doesn't succeed, you can | ||
write error handling based on ``result``. | ||
|
||
.. include:: /examples/generated/react-native/v12/Login.snippet.user-provider-fallback.tsx.rst | ||
|
||
User Sessions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since there are so many H2s on this page, would it help to nest all of the auth methods as H3s under an "Authenticate Users" (or something) parent heading? to better visually group them and separate from the other headings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll experiment! I was wondering the same thing at some point, but didn't get around to it.
examples/react-native/v12/TestApp/src/components/authentication/login/LoginWithEmail.tsx
Outdated
Show resolved
Hide resolved
examples/react-native/v12/TestApp/src/components/authentication/login/RealmWrapper.tsx
Outdated
Show resolved
Hide resolved
source/sdk/react-native/manage-users/manage-email-password-users.txt
Outdated
Show resolved
Hide resolved
source/sdk/react-native/manage-users/manage-email-password-users.txt
Outdated
Show resolved
Hide resolved
application can call :js-sdk:`EmailPasswordAuth.resetPassword() | ||
<Realm.Auth.EmailPasswordAuth.html#resetPassword>` to complete the password | ||
reset flow. | ||
application can use the :realm-react-sdk:`useEmailPasswordAuth hook |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this mostly applies to the Authenticate Users page, but it seemed like we weren't linking out to the API ref much/at all when referring to the useAuth
and useUser
hooks
Co-authored-by: cbullinger <[email protected]>
- Updated link identities sample - Figuring out new babel bug
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
onPress={() => { | ||
performAnonymousLogin(); | ||
}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onPress={() => { | |
performAnonymousLogin(); | |
}} | |
onPress={logInWithAnonymous} |
This could be simplified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I've been omitting the UI bits of of components for the auth stuff. Bluehawk removes everything between :remove-start:
and :remove-end:
so that we get samples like what's on the page: https://preview-mongodbkrollinsmdb.gatsbyjs.io/realm/DOCSP-27838/sdk/react-native/manage-users/authenticate-users/#anonymous-user
In this case, we could probably include the UI, as there's not much. But in other cases, the UI can be a lot and isn't really what we're focusing on. I think I'll keep this one as-is so it's consistent with the other examples.
I'd be happy to hear your thoughts on the balance between concise examples and "complete" examples though!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this urge to comment spawned on this block:
const performAnonymousLogin = () => {
logInWithAnonymous();
};
One could simply provide logInWithAnonymous
without wrapping it in a function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh. Yeah, that's a great point. ha! Thank you. I'll update other spots in the code that follow this pattern. Not sure why I got so wrapper happy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I initially misunderstood what you meant. Thank you for clarifying!
✨ Staging URL: https://preview-mongodbmongodb.gatsbyjs.io/realm/master/ 🪵 Logs |
Pull Request Info
This is a somewhat large PR, but don't let the lines changed intimidate you: that's mostly from the auto-generated
package-lock.json
file.I only address some of the needed auth changes in this PR. I created a small Jira epic to track the other work.
Major changes:
The test suite has an issue with randomly aborting. I have a Jira ticket to track fixing it.
Jira
Staged Changes
Much of the content and examples for the new hook reference tables comes from Andrew Meyer's additions to the Realm.js repo.
useAuth
.useEmailPasswordAuth
.Review Guidelines
REVIEWING.md
Animal Wearing a Hat