docs: new + improved auth documentation pages (#7529)

* added and improved auth docs

* add prep to generates resources action

* add module options to sidebar

* fix broken link
This commit is contained in:
Shahed Nasser
2024-06-09 15:18:29 +02:00
committed by GitHub
parent 3f661c917b
commit e472aed00f
17 changed files with 958 additions and 265 deletions
@@ -0,0 +1,74 @@
export const metadata = {
title: `How to Register a Customer with Email and Password`,
}
# {metadata.title}
In this guide, you'll learn the steps to register and authenticate a customer.
<Note title="Steps Summary">
1. Send a `POST` request to `/auth/customer/emailpass`.
2. Send a request to the [Create Customer API route](!api!/store#customers_postcustomers) passing the token obtained from the first step as a bearer token.
3. Send a `POST` request to `/auth/customer/emailpass` to log-in.
</Note>
## 1. Obtain Authentication Token
Before registering and creating the customer, you must create an authentication identity that's associated with that customer.
To do that, use the `/auth/customer/{provider}` API route, where `{provider}` is the auth provider to use to handle authentication.
<Note>
Learn more about the `/auth` route in [this document](../../auth/authentication-route/page.mdx)
</Note>
For example, send a `POST` request to `/auth/customer/emailpass`:
```bash
curl -X POST 'http://localhost:9000/auth/customer/emailpass' \
--header 'Content-Type: application/json' \
--data-raw '{
"email": "customer@gmail.com",
"password": "supersecret"
}'
```
---
## 2. Register Customer
Then, use the returned token in the header of the [Create Customer API route](!api!/store#customers_postcustomers):
```bash
curl -X POST 'http://localhost:9000/store/customers' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer {token}' \
--data-raw '{
"email": "customer@gmail.com",
"first_name": "John",
"last_name": "Doe"
}'
```
This creates and returns the customer.
---
## 3. Login Customer
Finally, to log-in the customer, send a `POST` request again to `/auth/customer/emailpass`:
```bash
curl -X POST 'http://localhost:9000/auth/customer/emailpass' \
--header 'Content-Type: application/json' \
--data-raw '{
"email": "customer@gmail.com",
"password": "supersecret"
}'
```
You can now use the returned token to send authenticated requests as a customer.