docs: added customer storefront guides (#7685)
* added customer guides * fixes to sidebar * remove old customer registration guide * fix build error * generate files * run linter
This commit is contained in:
1 parent
d862d03de0
commit
c1db40b564
80 files changed
+2301
-701
No files matched your search
@@ -122,11 +122,11 @@ In this guide, you’ll find common examples of how you can use the API Key Modu
|
||||
```ts collapsibleLines="1-9" expandButtonLabel="Show Imports"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse
|
||||
MedusaResponse,
|
||||
} from "@medusajs/medusa"
|
||||
import { IApiKeyModuleService } from "@medusajs/types"
|
||||
import {
|
||||
ModuleRegistrationName
|
||||
ModuleRegistrationName,
|
||||
} from "@medusajs/modules-sdk"
|
||||
|
||||
export async function POST(
|
||||
@@ -139,7 +139,7 @@ In this guide, you’ll find common examples of how you can use the API Key Modu
|
||||
const revokedKey = await apiKeyModuleService.revoke(
|
||||
request.params.id,
|
||||
{
|
||||
revoked_by: request.auth_context.actor_id
|
||||
revoked_by: request.auth_context.actor_id,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -175,7 +175,7 @@ In this guide, you’ll find common examples of how you can use the API Key Modu
|
||||
const revokedKey = await apiKeyModuleService.revoke(
|
||||
params.id,
|
||||
{
|
||||
revoked_by: params.user_id
|
||||
revoked_by: params.user_id,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -260,7 +260,7 @@ In this guide, you’ll find common examples of how you can use the API Key Modu
|
||||
```ts collapsibleLines="1-8" expandButtonLabel="Show Imports"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse
|
||||
MedusaResponse,
|
||||
} from "@medusajs/medusa"
|
||||
import { IApiKeyModuleService } from "@medusajs/types"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
@@ -275,7 +275,7 @@ In this guide, you’ll find common examples of how you can use the API Key Modu
|
||||
const revokedKey = await apiKeyModuleService.revoke(
|
||||
request.params.id,
|
||||
{
|
||||
revoked_by: request.auth_context.actor_id
|
||||
revoked_by: request.auth_context.actor_id,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -315,7 +315,7 @@ In this guide, you’ll find common examples of how you can use the API Key Modu
|
||||
const apiKeyModuleService = await initializeApiKeyModule()
|
||||
|
||||
const revokedKey = await apiKeyModuleService.revoke(params.id, {
|
||||
revoked_by: params.user_id
|
||||
revoked_by: params.user_id,
|
||||
})
|
||||
|
||||
const newKey = await apiKeyModuleService.create({
|
||||
|
||||
@@ -53,7 +53,7 @@ Revoke keys to disable their use permenantly.
|
||||
|
||||
```ts
|
||||
const revokedKey = await apiKeyModuleService.revoke("apk_1", {
|
||||
revoked_by: "user_123"
|
||||
revoked_by: "user_123",
|
||||
})
|
||||
```
|
||||
|
||||
@@ -63,7 +63,7 @@ Roll API keys by revoking a key then re-creating it.
|
||||
|
||||
```ts
|
||||
const revokedKey = await apiKeyModuleService.revoke("apk_1", {
|
||||
revoked_by: "user_123"
|
||||
revoked_by: "user_123",
|
||||
})
|
||||
|
||||
const newKey = await apiKeyModuleService.create({
|
||||
|
||||
@@ -57,9 +57,9 @@ const modules = {
|
||||
callbackURL: process.env.GOOGLE_CALLBACK_URL,
|
||||
successRedirectUrl:
|
||||
process.env.GOOGLE_SUCCESS_REDIRECT_URL,
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
@@ -36,8 +36,8 @@ const modules = {
|
||||
config: {
|
||||
emailpass: {
|
||||
// options...
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -92,4 +92,4 @@ const modules = {
|
||||
|
||||
## Related Guides
|
||||
|
||||
- [How to register a customer using email and password](../../../customer/register-customer-email/page.mdx)
|
||||
- [How to register a customer using email and password](../../../../storefront-development/customers/register/page.mdx)
|
||||
@@ -32,12 +32,12 @@ module.exports = defineConfig({
|
||||
http: {
|
||||
authMethodsPerActor: {
|
||||
user: ["google"],
|
||||
customer: ["emailpass"]
|
||||
customer: ["emailpass"],
|
||||
},
|
||||
// ...
|
||||
},
|
||||
// ...
|
||||
}
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
|
||||
@@ -32,6 +32,6 @@ There are two ways the returned authentication token is useful:
|
||||
|
||||
<Note title="Example">
|
||||
|
||||
[How to register Customers using the authentication route](../../customer/register-customer-email/page.mdx).
|
||||
[How to register Customers using the authentication route](../../../storefront-development/customers/register/page.mdx).
|
||||
|
||||
</Note>
|
||||
@@ -60,10 +60,10 @@ export const workflowHighlights = [
|
||||
import {
|
||||
createWorkflow,
|
||||
createStep,
|
||||
StepResponse
|
||||
StepResponse,
|
||||
} from "@medusajs/workflows-sdk"
|
||||
import {
|
||||
setAuthAppMetadataStep
|
||||
setAuthAppMetadataStep,
|
||||
} from "@medusajs/core-flows"
|
||||
import ManagerModuleService from "../modules/manager/service"
|
||||
|
||||
@@ -86,7 +86,7 @@ type CreateManagerWorkflowOutput = {
|
||||
const createManagerStep = createStep(
|
||||
"create-manager-step",
|
||||
async ({
|
||||
manager: managerData
|
||||
manager: managerData,
|
||||
}: Pick<CreateManagerWorkflowInput, "manager">,
|
||||
{ container }) => {
|
||||
const managerModuleService: ManagerModuleService =
|
||||
@@ -106,13 +106,13 @@ const createManagerWorkflow = createWorkflow<
|
||||
"create-manager",
|
||||
function (input) {
|
||||
const manager = createManagerStep({
|
||||
manager: input.manager
|
||||
manager: input.manager,
|
||||
})
|
||||
|
||||
setAuthAppMetadataStep({
|
||||
authIdentityId: input.authIdentityId,
|
||||
actorType: "manager",
|
||||
value: manager.id
|
||||
value: manager.id,
|
||||
})
|
||||
|
||||
return manager
|
||||
@@ -146,7 +146,7 @@ export const createRouteHighlights = [
|
||||
```ts title="src/api/manager/route.ts" highlights={createRouteHighlights}
|
||||
import type {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse
|
||||
MedusaResponse,
|
||||
} from "@medusajs/medusa"
|
||||
import { MedusaError } from "@medusajs/utils"
|
||||
import createManagerWorkflow from "../../workflows/create-manager"
|
||||
@@ -174,8 +174,8 @@ export async function POST(
|
||||
.run({
|
||||
input: {
|
||||
manager: req.body,
|
||||
authIdentityId: req.auth_context.auth_identity_id
|
||||
}
|
||||
authIdentityId: req.auth_context.auth_identity_id,
|
||||
},
|
||||
})
|
||||
|
||||
res.status(200).json({ manager: result })
|
||||
@@ -213,7 +213,7 @@ export const config: MiddlewaresConfig = {
|
||||
method: "POST",
|
||||
middlewares: [
|
||||
authenticate("manager", ["session", "bearer"], {
|
||||
allowUnregistered: true
|
||||
allowUnregistered: true,
|
||||
}),
|
||||
],
|
||||
},
|
||||
@@ -239,9 +239,9 @@ For example, create the file `src/api/manager/me/route.ts` with the following co
|
||||
```ts title="src/api/manager/me/route.ts"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse
|
||||
} from "@medusajs/medusa";
|
||||
import ManagerModuleService from "../../../modules/manager/service";
|
||||
MedusaResponse,
|
||||
} from "@medusajs/medusa"
|
||||
import ManagerModuleService from "../../../modules/manager/service"
|
||||
|
||||
export async function GET(
|
||||
req: AuthenticatedMedusaRequest,
|
||||
|
||||
@@ -37,8 +37,8 @@ module.exports = defineConfig({
|
||||
config: {
|
||||
google: {
|
||||
// provider options...
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
@@ -84,11 +84,11 @@ For example:
|
||||
```ts title="src/api/store/custom/route.ts"
|
||||
import {
|
||||
MedusaRequest,
|
||||
MedusaResponse
|
||||
MedusaResponse,
|
||||
} from "@medusajs/medusa"
|
||||
import { IAuthModuleService } from "@medusajs/types"
|
||||
import {
|
||||
ModuleRegistrationName
|
||||
ModuleRegistrationName,
|
||||
} from "@medusajs/modules-sdk"
|
||||
|
||||
export async function GET(
|
||||
@@ -111,7 +111,7 @@ For example:
|
||||
import { SubscriberArgs } from "@medusajs/medusa"
|
||||
import { IAuthModuleService } from "@medusajs/types"
|
||||
import {
|
||||
ModuleRegistrationName
|
||||
ModuleRegistrationName,
|
||||
} from "@medusajs/modules-sdk"
|
||||
|
||||
export default async function subscriberHandler({
|
||||
@@ -131,7 +131,7 @@ For example:
|
||||
import { createStep } from "@medusajs/workflows-sdk"
|
||||
import { IAuthModuleService } from "@medusajs/types"
|
||||
import {
|
||||
ModuleRegistrationName
|
||||
ModuleRegistrationName,
|
||||
} from "@medusajs/modules-sdk"
|
||||
|
||||
const step1 = createStep(
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
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.
|
||||
@@ -38,14 +38,14 @@ module.exports = defineConfig({
|
||||
config: {
|
||||
manual: {
|
||||
// provider options...
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
|
||||
@@ -124,7 +124,7 @@ module.exports = defineConfig({
|
||||
],
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
|
||||
@@ -60,14 +60,14 @@ module.exports = defineConfig({
|
||||
apiKey: process.env.STRIPE_USD_API_KEY,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
|
||||
@@ -213,7 +213,7 @@ In this guide, you’ll find common examples of how you can use the Product Modu
|
||||
request.scope.resolve(ModuleRegistrationName.PRODUCT)
|
||||
|
||||
const data = await productModuleService.list({
|
||||
handle: "shirt"
|
||||
handle: "shirt",
|
||||
})
|
||||
|
||||
res.json({ product: data[0] })
|
||||
@@ -234,7 +234,7 @@ In this guide, you’ll find common examples of how you can use the Product Modu
|
||||
const productModuleService = await initializeProductModule()
|
||||
|
||||
const data = await productModuleService.list({
|
||||
handle: "shirt"
|
||||
handle: "shirt",
|
||||
})
|
||||
|
||||
return NextResponse.json({ product: data[0] })
|
||||
|
||||
@@ -24,7 +24,7 @@ const promotion = await promotionModuleService.create({
|
||||
type: "percentage",
|
||||
target_type: "order",
|
||||
value: "10",
|
||||
currency_code: "usd"
|
||||
currency_code: "usd",
|
||||
},
|
||||
})
|
||||
```
|
||||
@@ -41,7 +41,7 @@ const promotion = await promotionModuleService.create({
|
||||
type: "percentage",
|
||||
target_type: "order",
|
||||
value: "10",
|
||||
currency_code: "usd"
|
||||
currency_code: "usd",
|
||||
},
|
||||
rules: [
|
||||
{
|
||||
|
||||
@@ -60,7 +60,7 @@ const regions = await regionModuleService.create([
|
||||
name: "United States of America",
|
||||
currency_code: "usd",
|
||||
countries: ["us"],
|
||||
payment_providers: ["stripe"]
|
||||
payment_providers: ["stripe"],
|
||||
},
|
||||
])
|
||||
```
|
||||
|
||||
@@ -34,7 +34,7 @@ const stores = await storeModuleService.create([
|
||||
{
|
||||
name: "Europe Store",
|
||||
supported_currency_codes: ["eur"],
|
||||
}
|
||||
},
|
||||
])
|
||||
```
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ module.exports = defineConfig({
|
||||
],
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ module.exports = defineConfig({
|
||||
jwt_secret: process.env.JWT_SECRET,
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
|
||||
Reference in new issue
Block a user