gladly-team / next-firebase-auth

Simple Firebase authentication for all Next.js rendering strategies
https://nfa-example-git-v1x-gladly-team.vercel.app/
MIT License
1.34k stars 291 forks source link

Add metaData / user data to AuthUser object #630

Closed SaadBazaz closed 1 year ago

SaadBazaz commented 1 year ago

Is your feature request related to a problem? Please describe. I currently have to manage user state through either Redux, or useContext. I was wondering, since AuthUser is already everywhere in the app, why not use it to store User Data as well?

Describe the solution you'd like and how you'd implement it Perhaps a setter function to set AuthUser Metadata.

Is this a breaking change? Not really. If implemented the right way, it should be totally backwards compatible.

kmjennison commented 1 year ago

Thanks for the suggestion. This feels a little out of scope to me. An app typically will manage more than just user-related state, and of course people shouldn't attach non-user app state to AuthUser. In my mind, the better pattern is the reverse: if you have a state management system, you could consider putting AuthUser data into it, if it's useful to have things in one place. Thoughts?

SaadBazaz commented 1 year ago

Thanks for the suggestion. This feels a little out of scope to me. An app typically will manage more than just user-related state, and of course people shouldn't attach non-user app state to AuthUser. In my mind, the better pattern is the reverse: if you have a state management system, you could consider putting AuthUser data into it, if it's useful to have things in one place. Thoughts?

Yes, that's how I'm currently doing it. It's just the problem of sync and revalidation. For example, if I do X action, I'd like to refresh AuthUser.

kmjennison commented 1 year ago

Trying to understand this better: What do you mean by "refreshing" AuthUser? Do you mean force-refreshing the ID token (for example, to update claims)? How are you currently accessing AuthUser data and refreshing it?

kmjennison commented 1 year ago

Closing this, as I believe this is out of scope for this library.