Build your own marketplace from scratch using Medusa
sales_channels
feature flag by clicking here.
User
linked to a Store
(where the User
acts as a vendor, it’s distinct from a Customer
).
User
entity:
Store
entity to include a new property representing our OneToMany
relationship, which is necessary to avoid type errors in the previously extended User
model :
User
and Store
entities, we proceed with a database migration to reflect these changes in the schema. We continue following the recipe by executing the following command in our terminal:
up
and down
functions in our new migration with the ones provided in the docs :
store_id
column in the user
table!
userService
.
We then register the loggedInUser
value in the request scope, which can be accessed by other services and components.
/admin
routes, except for a few specific routes that don’t require authentication (This is why the long regex)UserService
to automatically create a new store when a new user is registered. This will ensure that every user has a store associated with their account, which is a key requirement for our marketplace :
UserService
, we override the create
method to check if the user has a store_id
associated with their account. If not, we create a new store and associate it with the user’s account before creating the new user.
Let’s run our server and try to create a new User
, we can use Postman or HTTPie to make a POST
request to /admin/users
when logged-in.
Let’s try with a simple payload like this one :
User
a new Store
is associated to it !
ADMIN_CORS
in your .env
fileloggedInUser
is undefined
or null
LIFE_TIME
services to TRANSIENT
, it should fix the issues :
store_id
with the creation of a product etc., before moving on to the “events/subscribers” part.
We’re not going to tackle events just yet, but rather continue to focus on service management and how to extend them so as to have everything nicely tied up to a vendor.