strapi save the items to db

Good afternoon everyone. Please tell me how do I implement saving the user’s purchase history in the database?
I understand how to make a local save, but I want the user’s basket of products to be saved until he cleans it himself. Or the history of visiting products . I watched a bunch of videos and didn’t understand how I could make the shopping cart and the history of visiting goods stored for the user in the database

I am using the latest version of strapi + next js