docs: triage issues + revamp troubleshooting guides (#14216)
* docs: triage issues + revamp troubleshooting guides * small change
This commit is contained in:
@@ -28,12 +28,12 @@ To register a customer, you implement the following steps:
|
||||
|
||||
1. Show the customer a form to enter their details.
|
||||
2. Send a `POST` request to the `/auth/customer/emailpass/register` [Get Registration Token](!api!/store#auth_postactor_typeauth_provider_register) API route to obtain a registration JWT token.
|
||||
3. Send a request to the [Create Customer API route](!api!/store#customers_postcustomers) passing the registration JWT token in the header.
|
||||
3. Send a request to the [Register Customer API route](!api!/store#customers_postcustomers) passing the registration JWT token in the header.
|
||||
|
||||
However, a customer may enter an email that's already used either by an admin user, another customer, or a [custom actor type](../../../commerce-modules/auth/auth-identity-and-actor-types/page.mdx). To handle this scenario:
|
||||
|
||||
- Try to obtain a login token by sending a `POST` request to the `/auth/customer/emailpass` [Authenticate Customer](!api!/store#auth_postactor_typeauth_provider) API route. The customer is only allowed to register if their email and password match the existing identity. This allows admin users to log in or register as customers.
|
||||
- If you obtained the login token successfully, create the customer using the login JWT token instead of the registration token. This will not remove the existing identity. So, for example, an admin user can also become a customer.
|
||||
- If you obtained the login token successfully, register the customer using the login JWT token instead of the registration token. This will not remove the existing identity. So, for example, an admin user can also become a customer.
|
||||
|
||||
When you're using the JS SDK, this flow is simplified with quick registration and login methods. The rest of this guide uses the JS SDK to demonstrate the registration flow. However, if you're not using the JS SDK, you can still implement the same flow using the API routes.
|
||||
|
||||
@@ -186,7 +186,7 @@ export const fetchHighlights = [
|
||||
["11", "catch", "Maybe another identity exists with the same email."],
|
||||
["21", "login", "Try to obtain a login JWT token."],
|
||||
["24", "catch", "The existing account belongs to another customer, so authentication failed."],
|
||||
["40", "create", "Send a request to create the customer."],
|
||||
["40", "create", "Send a request to register the customer."],
|
||||
["47", "TODO", "Redirect the customer to the log in page."],
|
||||
["48", "catch", "Handle registration failure"],
|
||||
]
|
||||
@@ -211,7 +211,7 @@ export const fetchHighlights = [
|
||||
}
|
||||
// another identity (for example, admin user)
|
||||
// exists with the same email. So, use the auth
|
||||
// flow to login and create a customer.
|
||||
// flow to login and register a customer.
|
||||
const loginResponse = (await sdk.auth.login("customer", "emailpass", {
|
||||
email,
|
||||
password,
|
||||
@@ -229,7 +229,7 @@ export const fetchHighlights = [
|
||||
}
|
||||
}
|
||||
|
||||
// create customer
|
||||
// register customer
|
||||
try {
|
||||
const { customer } = await sdk.store.customer.create({
|
||||
first_name: firstName,
|
||||
@@ -256,7 +256,7 @@ In the above example, you create a `handleRegistration` function that:
|
||||
- If the error is an existing identity error, try retrieving the login JWT token from `/auth/customer/emailpass` API route using the `auth.login` method. This will fail if the existing identity has a different password, which doesn't allow the customer from registering.
|
||||
- For other errors, show an alert and exit execution.
|
||||
- The JS SDK automatically stores an re-uses the authentication headers or session in the `auth.register` and `auth.login` methods. So, if you're not using the JS SDK, make sure to pass the received authentication tokens as explained in the [API reference](!api!/store#1-bearer-authorization-with-jwt-tokens)
|
||||
- Send a request to the [Create Customer API route](!api!/store#customers_postcustomers) to create the customer in Medusa.
|
||||
- Send a request to the [Register Customer API route](!api!/store#customers_postcustomers) to register the customer in Medusa.
|
||||
- If an error occurs, show an alert and exit execution.
|
||||
- As mentioned, the JS SDK automatically sends the authentication headers or session in all requests after registration or logging in. If you're not using the JS SDK, make sure to pass the received authentication tokens as explained in the [API reference](!api!/store#1-bearer-authorization-with-jwt-tokens).
|
||||
- Once the customer is registered successfully, you can either redirect the customer to the login page or log them in automatically, as explained in the [Login](../login/page.mdx) guide.
|
||||
|
||||
Reference in New Issue
Block a user