One more thing that I want to talk about before we end the tutorial is private media collection and I want to give you a warning and a word of caution here because I didn't have enough time to test this out so just be careful and test out the app make sure you can still see all the images that you should be able to see it's gonna be a very simple change and this is why So let me go ahead and do bun run dev and go to localhost 3000. After that, go ahead and create a completely new account. So for the first time, just create a brand new account. So for example I'm going to use I don't know hello, hello demo.com and demo and once I create this account I'm gonna go ahead into the dashboard And no need to verify this entire thing yet. All we are going to do is enter the user's tenant, and we are going to attempt to add an image for our tenant store.
So go inside of the tenants, select your new tenant, and here's the thing. If you click choose from existing, You can find all media from all other users. And this is kind of the thing I find problematic, right? So you shouldn't be able to see any of these things. So what we are going to do, again, Word of caution, I have not tested this yet.
What we are going to do is the following. Let's do bun run database fresh, so we have a completely blank database. Confirm that you want to drop it and this error is okay it's simply telling us we don't have any migration files. After that wait a few seconds and go ahead and seed your database. Once you have seeded your database go ahead and run bun run dev.
And after that, go to payload.config.ts and go inside of the multi-tenant plugin and add media alongside our products here. So just as our products are private in CMS, so in CMS, the only people who can access the products are the tenants of that product. When it comes to our local API, Of course, anyone can see them, but in the CMS, it's important that only the tenant can see them. And after you do this change, you should also get another change in your payload types. If you are not seeing that change, you might have to run generateTypes separately.
So let's do banner.run generateTypes. So this should generate new types for me and you're going to see that in a second. And once it's completed, you will now see a new file here, Payload Types, which basically adds the tenant field to the media interface, and also down here for some media select querying options. So all I'm going to do now is just go to my localhost 3000 here, and I'm going to repeat the process. I'm going to create a new user completely.
So I only have my categories here. So I'm just gonna go ahead and create a new user, AntonioDemo.com. Let me just reverse these things. Let's create an account. And after you create an account, let's go ahead and try adding an image for our store by going inside of the tenant.
So tenants right here and demo and let's click create new and let's click select a File. So I'm just going to select an image. I will add some alt text and click Save. And it looks like it is working, right? So, perfect.
I now have this media. I will click Save. This works great. Only I can see my media now. And now I'm going to log out.
And I will create a completely new account. So john, johndemo.com, demo. And now I'm going to see if I can see that in here. So choose from existing. There we go.
We have successfully privatized media. So now one more thing to make sure is that I can go for example to slash tenants slash Antonio. So I just want to see that I can load Antonio's store And I'm just not sure did I create my username correctly. So tenant not found. What did I call myself?
If not, Antonio, I'm not sure. Or maybe I don't allow the store unless I'm verified. So basically, it's important for you to just test your app more specifically, because I don't know if this will cause any issues. So let me just add a note here, please test your app. I think that this should work just fine, but go ahead and test out your app, ensure that you can still add new images to your products and that they're visible.
The only thing that should be different is that now it should only be visible in the CMS to the author who uploaded that image. And one more thing that we can do in this chapter, which is just a funny thing I forgot, inside of the product view right here in the products module. In here, we have a button called cart button. Let me just find it here. Basically, This is where we import it, cart button.
So go inside of UI components cart button. And this is actually problematic because what it does is it will try to redirect you in production. It will try to redirect you to Antonio.funroad.dev slash library. That doesn't exist. It should lead to funroad.dev library.
So go ahead and add process environment node, my apologies, just next public app URL, like this, and remove prefetch. So if it's purchased, this is the URL we should redirect the user to. So that's another bug that we had. Hopefully, you will watch to the end so you can see me fix this. Great, so what I'm going to do now is just git add this, git commit changes, and I will do git push, and I will just confirm that we didn't introduce any new deployment errors so I think this is there we go so this one seven seconds ago I'm just going to pause and when I confirm that we didn't break the deployment, that's it.
That will be the very last chapter. Here we go. Looks like we didn't break the production, which is great news. And that officially means this is our last chapter. So we have made media private.
We pushed the GitHub and we deployed to Vercel. I would highly suggest that you test your app after this, not because it thinks something will break, but I didn't have time to develop with this feature turned on initially, right? So during my first build, I didn't do this. I forgot to do it. So I can tell you with confidence that this will all work out of the box.
Using what I know so far, it definitely should work without any problems, but please be careful, just test your app before, you know, going to production and actually selling things here. Amazing, amazing job. Thank you so much for watching and see you in the next tutorial.