From the course: Vue.js: Creating and Hosting a Full-Stack Site

Unlock this course with a free trial

Join today to access over 25,600 courses taught by industry experts.

Managing cart items with authentication

Managing cart items with authentication

- [Instructor] All right, so the last thing that we're going to see how to do here is add items to the user's cart with our new authentication setup, as well as remove items from the user's cart. Now, the first thing that we're going to have to do here in order to make sure everything works properly is we're going to have to make one important change to our server, right? Because currently, we only have one user in our database, and that's the user with the ID, 12345, that we put there earlier. So what we're going to need to do is when our server receives a request to add an item to the cart and we don't already have a user with that ID in the database, we're going to need to add a new user with that ID. So if you scroll down to the post endpoint for adding a new item to a user's cart, what we're going to want to do here is before we call db.collection, users, .updateOne, right? Which you'll notice if we don't already…

Contents