Skip to content

add options to useAuthState hook "onUserChanged" #139

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

Merged
merged 5 commits into from
Jan 4, 2022

Conversation

dohomi
Copy link
Contributor

@dohomi dohomi commented Mar 27, 2021

Add possibility to pass options for onUserChanged, a function which is called if a user auth state changed.
This might close #33

dohomi added 3 commits March 27, 2021 11:10
Add possibility to pass options for onUserLoaded, a function which is called if a user auth state changed.
This might close CSFrequency#33
// onUserLoaded function to process custom claims on any other trigger function
await options.onUserChanged(user)
}
setValue(user);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will never be executed if the passed handler fails. It should be considered to set the value first and then perform the handler.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mauriceackel or should it be wrapped in try .. catch ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively it could be mentioned that the onUserChanged should handle errors within that function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This definitely needs some error handling built in, otherwise it will be very difficult to debug any issues. I'd propose a try / catch, then re-using setError

@chrisbianca
Copy link
Contributor

Thanks @dohomi and apologies for the slow review of the PR. I think this is an interesting way of solving the problem and can't decide if this or a useIdTokenResult hook might be a better approach?

@dohomi
Copy link
Contributor Author

dohomi commented Apr 25, 2021

@chrisbianca I added a try catch block inside of the function. I followed the documentation of Firebase thats why I added the option into the result of the onUserChanged. I am not sure if useIdTokenResult is handling it in the same way.

@chrisbianca chrisbianca merged commit ba1c7e1 into CSFrequency:master Jan 4, 2022
@chrisbianca
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Auth with custom claims?
3 participants