Next.js Discord

Discord Forum

Storing Payment Status of Customer on the client

Answered
Giant panda posted this in #help-forum
Open in Discord
Giant pandaOP
What's the go-to/best practice approach to storing and accessing the payment status ( paid / free ) of a user across all components in the frontend? Local storage? Global State like Zustand ? React context? React Query? I'm already using the status on a server component but I need the status on an unrelated client component
Answered by B33fb0n3
it sounds like you fetch the data from the server. So I would build it's own react query that keeps track of the data and pass the initial as initialData to it. If I want to I can access them in every part of my app and control them freely
View full answer

7 Replies

@Giant panda What's the go-to/best practice approach to storing and accessing the payment status ( paid / free ) of a user across all components in the frontend? Local storage? Global State like Zustand ? React context? React Query? I'm already using the status on a server component but I need the status on an unrelated client component
it sounds like you fetch the data from the server. So I would build it's own react query that keeps track of the data and pass the initial as initialData to it. If I want to I can access them in every part of my app and control them freely
Answer
West African Lion
paid-free never store that in Client-side cache if its used to shield specific pages
you can do what B33f said, or what i prefer, if you are retrieving the data anyways it means the user is identified or authenticated, inject the payment status into the users JWT so when he authenticates to you, it is stored in his auth token cookie and you can just pull from that the entire time
@Giant panda solved?
Giant pandaOP
Solved, not able to mark it though
happy to help