I recently made something similar using React.Context to manage auth state. On some advice from @kentcdodds
he made a point how, if your entire app depends on an authorized user, it's much easier to handle it all in it's own module then just import user state in the files that need it, in the Components that are only rendered for an authorized user.
With firebase auth I'm just rendering a complete different root Component (App or Login) in my main index file like this:
But this could also be renderApp(user) and you could define routes appropriately in there. Easier to not have to check for user everywhere, and in each Component you can just:
I would get rid of
auth.js
. Seems like extra indirection for not much gain.You can refactor
action
in the form:Then in
Form.js
I recently made something similar using React.Context to manage auth state. On some advice from @kentcdodds he made a point how, if your entire app depends on an authorized user, it's much easier to handle it all in it's own module then just import user state in the files that need it, in the Components that are only rendered for an authorized user.
With firebase auth I'm just rendering a complete different root Component (App or Login) in my main index file like this:
But this could also be
renderApp(user)
and you could define routes appropriately in there. Easier to not have to check for user everywhere, and in each Component you can just:where needed, knowing the user is logged in at this point.