38 lines
1.0 KiB
Plaintext
38 lines
1.0 KiB
Plaintext
---
|
||
sidebar_label: "User Creation"
|
||
---
|
||
|
||
export const metadata = {
|
||
title: `User Creation`,
|
||
}
|
||
|
||
# {metadata.title}
|
||
|
||
In this document, you’ll 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 doesn’t 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 doesn’t 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,
|
||
})
|
||
}
|
||
```
|