docs: document registering user with existing email (#10859)

This commit is contained in:
Shahed Nasser
2025-01-07 12:39:16 +02:00
committed by GitHub
parent 632600ee11
commit f8c20e5ee4
5 changed files with 183 additions and 43 deletions
@@ -53,7 +53,7 @@ This method calls the `authenticate` method of the provider specified in the fir
The basic authentication flow requires first using the `register` method, then the `authenticate` method:
```ts
const { success, authIdentity } = await authModuleService.register(
const { success, authIdentity, error } = await authModuleService.register(
"emailpass",
// passed to auth provider
{
@@ -61,6 +61,12 @@ const { success, authIdentity } = await authModuleService.register(
}
)
if (error) {
// registration failed
// TODO return an error
return
}
// later (can be another route for log-in)
const { success, authIdentity, location } = await authModuleService.authenticate(
"emailpass",
@@ -87,6 +93,15 @@ Check out the [AuthIdentity](/references/auth/models/AuthIdentity) reference for
![Diagram showcasing the basic authentication flow](https://res.cloudinary.com/dza7lstvk/image/upload/v1711373749/Medusa%20Resources/basic-auth_lgpqsj.jpg)
### Auth Identity with Same Identifier
If an auth identity, such as a `customer`, tries to register with an email of another auth identity, the `register` method returns an error. This can happen either if another customer is using the same email, or an admin user has the same email.
There are two ways to handle this:
- Consider the customer authenticated if the `authenticate` method validates that the email and password are correct. This allows admin users, for example, to authenticate as customers.
- Return an error message to the customer, informing them that the email is already in use.
---
## Auth Flow 2: Third-Party Service Authentication