Files
medusa-store/www/apps/resources/app/commerce-modules/auth/user-creation/page.mdx
Shahed Nasser 2c5ba408d4 docs: edits and fixes to commerce module docs (#7468)
Apply edits and fixes to the commerce modules docs
2024-05-29 11:08:06 +00:00

38 lines
1.0 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
sidebar_label: "User Creation"
---
export const metadata = {
title: `User Creation`,
}
# {metadata.title}
In this document, youll learn about creating a user with the User Module after authentication.
## Creating a User using the User Module
The User Module provides user and invite management functionalities. However, it doesnt provide authentication functionalities or store any related data.
By combining the User and Auth Modules, you can use the Auth Module for authenticating users, and the User Module to manage those users.
So, when a user is authenticated, and you receive the `AuthIdentity` object, you can use it to create a user if it doesnt exist:
```ts
const { success, authIdentity } =
await authModuleService.authenticate("emailpass", {
// ...
})
// assuming authIdentity is defined
const [, count] = await userModuleService.listAndCount({
email: authIdentity.entity_id,
})
if (!count) {
const user = await userModuleService.create({
email: authIdentity.entity_id,
})
}
```