-
Notifications
You must be signed in to change notification settings - Fork 585
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
(@realm/react) useEmailPasswordAuth.register
should return a promise
#6180
Comments
For reacting to successful or failed login/registration, the idea is to use // Automatically logs the user in after successful registration.
useEffect(() => {
if (result.operation === AuthOperationName.Register && result.success) {
logIn({email, password});
}
}, [/* ... */]); The same pattern can be used with
Avoiding the need for try-catch: For the calling code to avoid having to catch potential errors from a returned promise, we could have realm/react return the const handleRegistration = () => {
const { error } = await register(/* ... */);
if (error) {
// ...
}
// ...
}; Even if this was changed to return a promise, I don't believe we'd have to break existing behavior 👍 |
I've been giving this some thought, and I think the reason I shied away from making this a In summary, if we made this a I ended up finding out that there is a proposal for a promise hook from the React team. Here is an interesting blog post about that, which also details a bit of the issues one faces when using promises within react components. |
Thanks for clarifying, @takameyer! Totally makes sense. I'll close this issue. The proposal for a promise hook looks interesting! |
Problem
For the
useEmailPasswordAuth()
hook, it would be great ifregister()
returned a promise instead ofvoid
. The SDK'sapp.emailPasswordAuth.registerUser
does that. Without returning a promise, it can be hard to work with a sequence of events, like linking identities.For example:
Solution
useEmailPasswordAuth.register
should return a promise that resolves based onapp.emailPasswordAuth.registerUser
's behavior.Alternatives
No response
How important is this improvement for you?
I would like to have it but have a workaround
Feature would mainly be used with
Atlas App Services: Auth or Functions etc
The text was updated successfully, but these errors were encountered: