I have successfully implemented a payment system where users can pay with cryptocurrency, and their balance gets updated accordingly. The server-side logic works perfectly, and the balance is correctly updated in the database.
However, I’m facing an issue where the updated balance is not reflected on the client side immediately after the transaction. The user has to logout and login to see the new balance.
What is the best approach to ensure the user’s balance updates on their session without requiring a page refresh? Here are a few methods I’ve considered:
-
Fetch Balance with No-Cache: Should I implement a no-cache fetch request to update the balance after the payment is processed?
-
Session Management: How can I update the user’s session with the new balance?
I would appreciate any insights or code examples on how to implement these or other methods effectively. My main goal is to provide a seamless experience where the balance is updated automatically right after the transaction.
Current fetch:
At the moment, I set the balance object during login in NextAuth (useSession), so I don’t have to fetch the user’s balance separately.
Thank you!