data needed from user after auth.
Answered
Spectacled Caiman posted this in #help-forum
Spectacled CaimanOP
Hi! New here and wanted some feedback on how to achieve something that most all apps do, return some what of larger amounts of data about a user as soon as someone logs in to the app and immediately pump that data into context to use anywhere in the app. Additionally how to revalidate that data say when a post request is done to update that data ? Thanks so much in advance!
Answered by B33fb0n3
that happens mostly only for user data, because user data normally not change that often. Then you also need to take a look at the auth method:
JWT: Client saves data, so you save most of the user data inside this jwt token. That can be an userId to request actual data (if important) or if you just want the user data you can directly get it from your jwt (no database request needed). This client data can be outdated.
Session: Client saves only session id. With the session id you can retrieve the current data from your database. This data is everytime fresh. Each data request need a database request.
So changing of data is different, retrieving data is different and revalidating is different as well. So you can have my first paragraph in mind and apply it your case
JWT: Client saves data, so you save most of the user data inside this jwt token. That can be an userId to request actual data (if important) or if you just want the user data you can directly get it from your jwt (no database request needed). This client data can be outdated.
Session: Client saves only session id. With the session id you can retrieve the current data from your database. This data is everytime fresh. Each data request need a database request.
So changing of data is different, retrieving data is different and revalidating is different as well. So you can have my first paragraph in mind and apply it your case
8 Replies
that happens mostly only for user data, because user data normally not change that often. Then you also need to take a look at the auth method:
JWT: Client saves data, so you save most of the user data inside this jwt token. That can be an userId to request actual data (if important) or if you just want the user data you can directly get it from your jwt (no database request needed). This client data can be outdated.
Session: Client saves only session id. With the session id you can retrieve the current data from your database. This data is everytime fresh. Each data request need a database request.
So changing of data is different, retrieving data is different and revalidating is different as well. So you can have my first paragraph in mind and apply it your case
JWT: Client saves data, so you save most of the user data inside this jwt token. That can be an userId to request actual data (if important) or if you just want the user data you can directly get it from your jwt (no database request needed). This client data can be outdated.
Session: Client saves only session id. With the session id you can retrieve the current data from your database. This data is everytime fresh. Each data request need a database request.
So changing of data is different, retrieving data is different and revalidating is different as well. So you can have my first paragraph in mind and apply it your case
Answer
Spectacled CaimanOP
Hey! It’s not super clear on the prefered method here but sounds like the jwt might be the way to go.
both have their advantages and their disadvantages. Depending on your use case you can decide which one suites more to your needs. You can see a quick overview here: https://velog.velcdn.com/images/devfish/post/6e8c7828-09d3-46c6-93cd-d683f31b0ae2/image.png
@Spectacled Caiman solved?
Spectacled CaimanOP
I think I found a strategy that makes sense. Basically fetch the data directly in the provider in a useEffect. Solved!
That’s not how you want to do it. However, if this thread is solved please mark solution
If this is not the solution, feel free to mark another message as solution
Spectacled CaimanOP
Oh you’re say this is not what to do. I guess I’ll have to weigh things out from a jwt / session