docs: added docs for reset password (#9306)

- Added to docs on implementing auth flows using the module and API routes how to update a user's password
- Added guide on how to send a notification when a password token is generated
- Added a guide on implementing reset password flow in storefront
- Added OAS for the `/update` and `/reset-password` routes + generated specs for the API reference
This commit is contained in:
Shahed Nasser
2024-10-07 11:04:01 +03:00
committed by GitHub
parent adb3a8246a
commit 781d0ca624
38 changed files with 1479 additions and 40 deletions
@@ -0,0 +1,5 @@
curl -X POST '{backend_url}/auth/user/emailpass/reset-password' \
-H 'Content-Type: application/json' \
--data-raw '{
"identifier": "admin@medusa-test.com"
}'
@@ -0,0 +1,6 @@
curl -X POST '{backend_url}/auth/user/emailpass/update?token=123' \
-H 'Content-Type: application/json' \
--data-raw '{
"email": "admin@medusa-test.com",
"password": "supersecret"
}'
@@ -44693,6 +44693,9 @@ paths:
type: object
title: input
description: The input data necessary for authentication. For example, for email-pass authentication, pass `email` and `password` properties.
example:
email: admin@medusa-test.com
password: supersecret
x-codeSamples:
- lang: Shell
label: cURL
@@ -44724,6 +44727,136 @@ paths:
$ref: '#/components/responses/invalid_request_error'
'500':
$ref: '#/components/responses/500_error'
/auth/user/{auth_provider}/reset-password:
post:
operationId: PostActor_typeAuth_providerResetPassword
summary: Generate Reset Password Token for Admin User
x-sidebar-summary: Generate Reset Password Token
description: |
Generate a reset password token for an admin user. This API route emits the `` event, passing it the token as a payload. You can listen to that event and send the user a notification. The notification should have a URL that accepts a `token` query parameter.
Use the generated token to update the user's password using the Reset Password API route.
externalDocs:
url: https://docs.medusajs.com/v2/resources/commerce-modules/auth/authentication-route#generate-reset-password-token-route
description: Learn more about this API route.
x-authenticated: false
parameters:
- name: auth_provider
in: path
description: The provider used for authentication.
required: true
schema:
type: string
example: emailpass
requestBody:
content:
application/json:
schema:
type: object
title: identifier
description: The user's identifier for the selected auth provider. For example, for the `emailpass` auth provider, the value is the user's email.
example: admin@medusa-test.com
x-codeSamples:
- lang: Shell
label: cURL
source: |-
curl -X POST '{backend_url}/auth/user/emailpass/reset-password' \
-H 'Content-Type: application/json' \
--data-raw '{
"identifier": "admin@medusa-test.com"
}'
tags:
- Auth
responses:
'201':
description: OK
'400':
$ref: '#/components/responses/400_error'
'401':
$ref: '#/components/responses/unauthorized'
'404':
$ref: '#/components/responses/not_found_error'
'409':
$ref: '#/components/responses/invalid_state_error'
'422':
$ref: '#/components/responses/invalid_request_error'
'500':
$ref: '#/components/responses/500_error'
x-workflow: generateResetPasswordTokenWorkflow
/auth/user/{auth_provider}/update:
post:
operationId: PostActor_typeAuth_providerUpdate
summary: Reset an Admin User's Password
x-sidebar-summary: Reset Password
description: Reset a user's password. Generate the reset password token first using the Get Reset Password Token API route.
externalDocs:
url: https://docs.medusajs.com/v2/resources/commerce-modules/auth/authentication-route#reset-password-route
description: Learn more about this API route.
x-authenticated: false
parameters:
- name: auth_provider
in: path
description: The provider used for authentication.
required: true
schema:
type: string
example: emailpass
- name: token
in: query
description: The reset password token received using the Get Reset Password API route.
required: true
schema:
type: string
requestBody:
content:
application/json:
schema:
type: object
title: input
description: The input data necessary for authentication. For example, for email-pass authentication, pass `email` and `password` properties.
example:
email: admin@medusa-test.com
password: supersecret
x-codeSamples:
- lang: Shell
label: cURL
source: |-
curl -X POST '{backend_url}/auth/user/emailpass/update?token=123' \
-H 'Content-Type: application/json' \
--data-raw '{
"email": "admin@medusa-test.com",
"password": "supersecret"
}'
tags:
- Auth
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
required:
- success
description: Details on the reset password's status.
properties:
success:
type: boolean
title: success
description: Whether the password was reset successfully.
'400':
$ref: '#/components/responses/400_error'
'401':
$ref: '#/components/responses/unauthorized'
'404':
$ref: '#/components/responses/not_found_error'
'409':
$ref: '#/components/responses/invalid_state_error'
'422':
$ref: '#/components/responses/invalid_request_error'
'500':
$ref: '#/components/responses/500_error'
components:
schemas:
AdminApiKey:
@@ -53047,19 +53180,19 @@ components:
exchange_id:
type: string
title: exchange_id
description: The return's exchange id.
description: The ID of the exchange that this return belongs to.
location_id:
type: string
title: location_id
description: The return's location id.
description: The ID of the location the items are returned to.
claim_id:
type: string
title: claim_id
description: The return's claim id.
description: The ID of the claim that this return belongs to.
order_version:
type: number
title: order_version
description: The return's order version.
description: The version of the order once the return is applied.
display_id:
type: number
title: display_id
@@ -1011,6 +1011,10 @@ paths:
$ref: paths/auth_user_{auth_provider}_callback.yaml
/auth/user/{auth_provider}/register:
$ref: paths/auth_user_{auth_provider}_register.yaml
/auth/user/{auth_provider}/reset-password:
$ref: paths/auth_user_{auth_provider}_reset-password.yaml
/auth/user/{auth_provider}/update:
$ref: paths/auth_user_{auth_provider}_update.yaml
components:
securitySchemes:
api_token:
@@ -27,6 +27,9 @@ post:
description: >-
The input data necessary for authentication. For example, for
email-pass authentication, pass `email` and `password` properties.
example:
email: admin@medusa-test.com
password: supersecret
x-codeSamples:
- lang: Shell
label: cURL
@@ -0,0 +1,58 @@
post:
operationId: PostActor_typeAuth_providerResetPassword
summary: Generate Reset Password Token for Admin User
x-sidebar-summary: Generate Reset Password Token
description: >
Generate a reset password token for an admin user. This API route emits the
`` event, passing it the token as a payload. You can listen to that event
and send the user a notification. The notification should have a URL that
accepts a `token` query parameter.
Use the generated token to update the user's password using the Reset Password API route.
externalDocs:
url: >-
https://docs.medusajs.com/v2/resources/commerce-modules/auth/authentication-route#generate-reset-password-token-route
description: Learn more about this API route.
x-authenticated: false
parameters:
- name: auth_provider
in: path
description: The provider used for authentication.
required: true
schema:
type: string
example: emailpass
requestBody:
content:
application/json:
schema:
type: object
title: identifier
description: >-
The user's identifier for the selected auth provider. For example,
for the `emailpass` auth provider, the value is the user's email.
example: admin@medusa-test.com
x-codeSamples:
- lang: Shell
label: cURL
source:
$ref: ../code_samples/Shell/auth_user_{auth_provider}_reset-password/post.sh
tags:
- Auth
responses:
'201':
description: OK
'400':
$ref: ../components/responses/400_error.yaml
'401':
$ref: ../components/responses/unauthorized.yaml
'404':
$ref: ../components/responses/not_found_error.yaml
'409':
$ref: ../components/responses/invalid_state_error.yaml
'422':
$ref: ../components/responses/invalid_request_error.yaml
'500':
$ref: ../components/responses/500_error.yaml
x-workflow: generateResetPasswordTokenWorkflow
@@ -0,0 +1,74 @@
post:
operationId: PostActor_typeAuth_providerUpdate
summary: Reset an Admin User's Password
x-sidebar-summary: Reset Password
description: >-
Reset a user's password. Generate the reset password token first using the
Get Reset Password Token API route.
externalDocs:
url: >-
https://docs.medusajs.com/v2/resources/commerce-modules/auth/authentication-route#reset-password-route
description: Learn more about this API route.
x-authenticated: false
parameters:
- name: auth_provider
in: path
description: The provider used for authentication.
required: true
schema:
type: string
example: emailpass
- name: token
in: query
description: >-
The reset password token received using the Get Reset Password API
route.
required: true
schema:
type: string
requestBody:
content:
application/json:
schema:
type: object
title: input
description: >-
The input data necessary for authentication. For example, for
email-pass authentication, pass `email` and `password` properties.
example:
email: admin@medusa-test.com
password: supersecret
x-codeSamples:
- lang: Shell
label: cURL
source:
$ref: ../code_samples/Shell/auth_user_{auth_provider}_update/post.sh
tags:
- Auth
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
required:
- success
description: Details on the reset password's status.
properties:
success:
type: boolean
title: success
description: Whether the password was reset successfully.
'400':
$ref: ../components/responses/400_error.yaml
'401':
$ref: ../components/responses/unauthorized.yaml
'404':
$ref: ../components/responses/not_found_error.yaml
'409':
$ref: ../components/responses/invalid_state_error.yaml
'422':
$ref: ../components/responses/invalid_request_error.yaml
'500':
$ref: ../components/responses/500_error.yaml
@@ -0,0 +1,5 @@
curl -X POST '{backend_url}/auth/customer/emailpass/reset-password' \
-H 'Content-Type: application/json' \
--data-raw '{
"identifier": "customer@gmail.com"
}'
@@ -0,0 +1,6 @@
curl -X POST '{backend_url}/auth/customer/emailpass/update?token=123' \
-H 'Content-Type: application/json' \
--data-raw '{
"email": "customer@gmail.com",
"password": "supersecret"
}'
@@ -157,8 +157,8 @@ paths:
When used with a third-party provider, such as Google, the request returns a `location` property. You redirect to the specified URL in your storefront to continue authentication with the third-party service.
externalDocs:
url: https://docs.medusajs.com/v2/resources/commerce-modules/auth/authentication-route#types-of-authentication-flows
description: Learn about different authentication flows.
url: https://docs.medusajs.com/v2/storefront-development/customers/login#1-using-a-jwt-token
description: 'Storefront development: How to login as a customer'
x-authenticated: false
parameters:
- name: auth_provider
@@ -222,8 +222,8 @@ paths:
You can decode the JWT token using libraries like [react-jwt](https://www.npmjs.com/package/react-jwt) in the storefront. If the decoded data doesn't have an `actor_id` property, then you must register the customer using the Create Customer API route passing the token in the request's Authorization header.
externalDocs:
url: https://docs.medusajs.com/v2/resources/commerce-modules/auth/authentication-route#2-third-party-service-authenticate-flow
description: Learn about third-party authentication flow.
url: https://docs.medusajs.com/v2/storefront-development/customers/third-party-login
description: 'Storefront development: Implement third-party (social) login.'
x-authenticated: false
parameters:
- name: auth_provider
@@ -267,8 +267,8 @@ paths:
summary: Retrieve Registration JWT Token
description: This API route retrieves a registration JWT token of a customer that hasn't been registered yet. The token is used in the header of requests that create a customer.
externalDocs:
url: https://docs.medusajs.com/v2/resources/commerce-modules/auth/authentication-route#1-basic-authentication-flow
description: Learn about the basic authentication flow.
url: https://docs.medusajs.com/v2/storefront-development/customers/register
description: 'Storefront development: How to register a customer'
x-authenticated: false
parameters:
- name: auth_provider
@@ -285,6 +285,9 @@ paths:
type: object
title: input
description: The input data necessary for authentication. For example, for email-pass authentication, pass `email` and `password` properties.
example:
email: customer@gmail.com
password: supersecret
x-codeSamples:
- lang: Shell
label: cURL
@@ -316,11 +319,144 @@ paths:
$ref: '#/components/responses/invalid_request_error'
'500':
$ref: '#/components/responses/500_error'
/auth/customer/{auth_provider}/reset-password:
post:
operationId: PostActor_typeAuth_providerResetPassword
summary: Generate Reset Password Token for Customer
x-sidebar-summary: Generate Reset Password Token
description: |
Generate a reset password token for a customer. This API route emits the `auth.password_reset` event, passing it the token as a payload. You can listen to that event and send the user a notification. The notification should have a URL that accepts a `token` query parameter.
Use the generated token to update the user's password using the Reset Password API route.
externalDocs:
url: https://docs.medusajs.com/v2/resources/storefront-development/customers/reset-password#1-request-reset-password-page
description: 'Storefront development: How to create the request reset password page.'
x-authenticated: false
parameters:
- name: auth_provider
in: path
description: The provider used for authentication.
required: true
schema:
type: string
example: emailpass
requestBody:
content:
application/json:
schema:
type: object
title: identifier
description: The customer's identifier for the selected auth provider. For example, for the `emailpass` auth provider, the value is the customer's email.
example: customer@gmail.com
x-codeSamples:
- lang: Shell
label: cURL
source: |-
curl -X POST '{backend_url}/auth/customer/emailpass/reset-password' \
-H 'Content-Type: application/json' \
--data-raw '{
"identifier": "customer@gmail.com"
}'
tags:
- Auth
responses:
'201':
description: OK
'400':
$ref: '#/components/responses/400_error'
'401':
$ref: '#/components/responses/unauthorized'
'404':
$ref: '#/components/responses/not_found_error'
'409':
$ref: '#/components/responses/invalid_state_error'
'422':
$ref: '#/components/responses/invalid_request_error'
'500':
$ref: '#/components/responses/500_error'
x-workflow: generateResetPasswordTokenWorkflow
/auth/customer/{auth_provider}/update:
post:
operationId: PostActor_typeAuth_providerUpdate
summary: Reset a Customer's Password
x-sidebar-summary: Reset Password
description: Reset a customer's password. Generate the reset password token first using the Get Reset Password Token API route.
externalDocs:
url: https://docs.medusajs.com/v2/resources/storefront-development/customers/reset-password#2-reset-password-page
description: 'Storefront development: How to create the reset password page.'
x-authenticated: false
parameters:
- name: auth_provider
in: path
description: The provider used for authentication.
required: true
schema:
type: string
example: emailpass
- name: token
in: query
description: The reset password token received using the Get Reset Password API route.
required: true
schema:
type: string
requestBody:
content:
application/json:
schema:
type: object
title: input
description: The input data necessary for authentication with the specified auth provider. For example, for email-pass authentication, pass `email` and `password` properties.
example:
email: customer@gmail.com
password: supersecret
x-codeSamples:
- lang: Shell
label: cURL
source: |-
curl -X POST '{backend_url}/auth/customer/emailpass/update?token=123' \
-H 'Content-Type: application/json' \
--data-raw '{
"email": "customer@gmail.com",
"password": "supersecret"
}'
tags:
- Auth
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
required:
- success
description: Details on the reset password's status.
properties:
success:
type: boolean
title: success
description: Whether the password was reset successfully.
'400':
$ref: '#/components/responses/400_error'
'401':
$ref: '#/components/responses/unauthorized'
'404':
$ref: '#/components/responses/not_found_error'
'409':
$ref: '#/components/responses/invalid_state_error'
'422':
$ref: '#/components/responses/invalid_request_error'
'500':
$ref: '#/components/responses/500_error'
/auth/session:
post:
operationId: PostSession
summary: Set Authentication Session
description: Set the cookie session ID of a customer. The customer must be previously authenticated with the `/auth/customer/{provider}` API route first, as the JWT token is required in the header of the request.
externalDocs:
url: https://docs.medusajs.com/v2/storefront-development/customers/login#2-using-a-cookie-session
description: 'Storefront development: How to login as a customer'
x-authenticated: true
x-codeSamples:
- lang: Shell
@@ -395,8 +531,8 @@ paths:
summary: Refresh Authentication Token
description: Refresh the authentication token of a customer. This is useful after authenticating a customer with a third-party service to ensure the token holds the new user's details, or when you don't want customers to re-login every day.
externalDocs:
url: https://docs.medusajs.com/v2/resources/commerce-modules/auth/authentication-route#2-third-party-service-authenticate-flow
description: Learn about third-party authentication flow.
url: https://docs.medusajs.com/v2/storefront-development/customers/third-party-login
description: 'Storefront development: Implement third-party (social) login.'
x-authenticated: true
x-codeSamples:
- lang: Shell
@@ -14630,19 +14766,19 @@ components:
exchange_id:
type: string
title: exchange_id
description: The return's exchange id.
description: The ID of the exchange that this return belongs to.
location_id:
type: string
title: location_id
description: The return's location id.
description: The ID of the location the items are returned to.
claim_id:
type: string
title: claim_id
description: The return's claim id.
description: The ID of the claim that this return belongs to.
order_version:
type: number
title: order_version
description: The return's order version.
description: The version of the order once the return is applied.
display_id:
type: number
title: display_id
@@ -195,6 +195,10 @@ paths:
$ref: paths/auth_customer_{auth_provider}_callback.yaml
/auth/customer/{auth_provider}/register:
$ref: paths/auth_customer_{auth_provider}_register.yaml
/auth/customer/{auth_provider}/reset-password:
$ref: paths/auth_customer_{auth_provider}_reset-password.yaml
/auth/customer/{auth_provider}/update:
$ref: paths/auth_customer_{auth_provider}_update.yaml
/auth/session:
$ref: paths/auth_session.yaml
/auth/token/refresh:
@@ -11,8 +11,8 @@ post:
continue authentication with the third-party service.
externalDocs:
url: >-
https://docs.medusajs.com/v2/resources/commerce-modules/auth/authentication-route#types-of-authentication-flows
description: Learn about different authentication flows.
https://docs.medusajs.com/v2/storefront-development/customers/login#1-using-a-jwt-token
description: 'Storefront development: How to login as a customer'
x-authenticated: false
parameters:
- name: auth_provider
@@ -17,8 +17,8 @@ post:
in the request's Authorization header.
externalDocs:
url: >-
https://docs.medusajs.com/v2/resources/commerce-modules/auth/authentication-route#2-third-party-service-authenticate-flow
description: Learn about third-party authentication flow.
https://docs.medusajs.com/v2/storefront-development/customers/third-party-login
description: 'Storefront development: Implement third-party (social) login.'
x-authenticated: false
parameters:
- name: auth_provider
@@ -6,9 +6,8 @@ post:
been registered yet. The token is used in the header of requests that create
a customer.
externalDocs:
url: >-
https://docs.medusajs.com/v2/resources/commerce-modules/auth/authentication-route#1-basic-authentication-flow
description: Learn about the basic authentication flow.
url: https://docs.medusajs.com/v2/storefront-development/customers/register
description: 'Storefront development: How to register a customer'
x-authenticated: false
parameters:
- name: auth_provider
@@ -27,6 +26,9 @@ post:
description: >-
The input data necessary for authentication. For example, for
email-pass authentication, pass `email` and `password` properties.
example:
email: customer@gmail.com
password: supersecret
x-codeSamples:
- lang: Shell
label: cURL
@@ -0,0 +1,60 @@
post:
operationId: PostActor_typeAuth_providerResetPassword
summary: Generate Reset Password Token for Customer
x-sidebar-summary: Generate Reset Password Token
description: >
Generate a reset password token for a customer. This API route emits the
`auth.password_reset` event, passing it the token as a payload. You can
listen to that event and send the user a notification. The notification
should have a URL that accepts a `token` query parameter.
Use the generated token to update the user's password using the Reset Password API route.
externalDocs:
url: >-
https://docs.medusajs.com/v2/resources/storefront-development/customers/reset-password#1-request-reset-password-page
description: 'Storefront development: How to create the request reset password page.'
x-authenticated: false
parameters:
- name: auth_provider
in: path
description: The provider used for authentication.
required: true
schema:
type: string
example: emailpass
requestBody:
content:
application/json:
schema:
type: object
title: identifier
description: >-
The customer's identifier for the selected auth provider. For
example, for the `emailpass` auth provider, the value is the
customer's email.
example: customer@gmail.com
x-codeSamples:
- lang: Shell
label: cURL
source:
$ref: >-
../code_samples/Shell/auth_customer_{auth_provider}_reset-password/post.sh
tags:
- Auth
responses:
'201':
description: OK
'400':
$ref: ../components/responses/400_error.yaml
'401':
$ref: ../components/responses/unauthorized.yaml
'404':
$ref: ../components/responses/not_found_error.yaml
'409':
$ref: ../components/responses/invalid_state_error.yaml
'422':
$ref: ../components/responses/invalid_request_error.yaml
'500':
$ref: ../components/responses/500_error.yaml
x-workflow: generateResetPasswordTokenWorkflow
@@ -0,0 +1,75 @@
post:
operationId: PostActor_typeAuth_providerUpdate
summary: Reset a Customer's Password
x-sidebar-summary: Reset Password
description: >-
Reset a customer's password. Generate the reset password token first using
the Get Reset Password Token API route.
externalDocs:
url: >-
https://docs.medusajs.com/v2/resources/storefront-development/customers/reset-password#2-reset-password-page
description: 'Storefront development: How to create the reset password page.'
x-authenticated: false
parameters:
- name: auth_provider
in: path
description: The provider used for authentication.
required: true
schema:
type: string
example: emailpass
- name: token
in: query
description: >-
The reset password token received using the Get Reset Password API
route.
required: true
schema:
type: string
requestBody:
content:
application/json:
schema:
type: object
title: input
description: >-
The input data necessary for authentication with the specified auth
provider. For example, for email-pass authentication, pass `email`
and `password` properties.
example:
email: customer@gmail.com
password: supersecret
x-codeSamples:
- lang: Shell
label: cURL
source:
$ref: ../code_samples/Shell/auth_customer_{auth_provider}_update/post.sh
tags:
- Auth
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
required:
- success
description: Details on the reset password's status.
properties:
success:
type: boolean
title: success
description: Whether the password was reset successfully.
'400':
$ref: ../components/responses/400_error.yaml
'401':
$ref: ../components/responses/unauthorized.yaml
'404':
$ref: ../components/responses/not_found_error.yaml
'409':
$ref: ../components/responses/invalid_state_error.yaml
'422':
$ref: ../components/responses/invalid_request_error.yaml
'500':
$ref: ../components/responses/500_error.yaml
@@ -5,6 +5,10 @@ post:
Set the cookie session ID of a customer. The customer must be previously
authenticated with the `/auth/customer/{provider}` API route first, as the
JWT token is required in the header of the request.
externalDocs:
url: >-
https://docs.medusajs.com/v2/storefront-development/customers/login#2-using-a-cookie-session
description: 'Storefront development: How to login as a customer'
x-authenticated: true
x-codeSamples:
- lang: Shell
@@ -8,8 +8,8 @@ post:
every day.
externalDocs:
url: >-
https://docs.medusajs.com/v2/resources/commerce-modules/auth/authentication-route#2-third-party-service-authenticate-flow
description: Learn about third-party authentication flow.
https://docs.medusajs.com/v2/storefront-development/customers/third-party-login
description: 'Storefront development: Implement third-party (social) login.'
x-authenticated: true
x-codeSamples:
- lang: Shell
@@ -45,6 +45,7 @@ This chapter provides links to example sections on different Medusa topics.
- [Execute a workflow in a subscriber](../../basics/workflows/page.mdx#3-execute-the-workflow)
- [Handle a custom event](../../customization/integrate-systems/handle-event/page.mdx)
- [Handle reset password token event](!resources!/commerce-modules/auth/reset-password)
---
@@ -8,7 +8,7 @@ export const metadata = {
# {metadata.title}
In this document, you'll learn how to use the Auth Module's main service's methods to implement an authentication flow.
In this document, you'll learn how to use the Auth Module's main service's methods to implement authentication flows and reset a user's password.
## Authentication Methods
@@ -149,3 +149,32 @@ if (success) {
If the returned `success` property is `true`, the authentication with the third-party provider was successful.
![Diagram showcasing the second part of the third-party authentication flow](https://res.cloudinary.com/dza7lstvk/image/upload/v1711375123/Medusa%20Resources/third-party-auth-2_kmjxju.jpg)
---
## Reset Password
To update a user's password or other authentication details, use the `updateProvider` method of the Auth Module's main service. It calls the `update` method of the specified authentication provider.
For example:
```ts
const { success } = await authModuleService.update(
"emailpass",
// passed to the auth provider
{
email: "user@example.com",
password: "supersecret",
}
)
if (success) {
// password reset successfully
}
```
The method accepts as a first parameter the ID of the provider, and as a second parameter the data necessary to reset the password.
In the example above, you use the `emailpass` provider, so you have to pass an object having an `email` and `password` properties.
If the returned `success` property is `true`, the password has reset successfully.
@@ -4,11 +4,11 @@ export const metadata = {
# {metadata.title}
In this document, you'll learn about the authentication routes and how to use them to create or log-in users.
In this document, you'll learn about the authentication routes and how to use them to create and log-in users, and reset their password.
<Note>
These routes are added by Medusa's application layer, not the Auth Module.
These routes are added by Medusa's HTTP layer, not the Auth Module.
</Note>
@@ -117,7 +117,7 @@ Use that token in the header of subsequent requests to send authenticated reques
---
## Auth Route
## Login Route
The Medusa application defines an API route at `/auth/{actor_type}/{provider}` that authenticates a user of an actor type. It returns a JWT token that can be passed in [the header of subsequent requests](!api!/store#authentication) to send authenticated requests.
@@ -238,4 +238,106 @@ If the token was refreshed successfully, you'll receive a `token` field in the r
}
```
Use that token in the header of subsequent requests to send authenticated requests.
Use that token in the header of subsequent requests to send authenticated requests.
---
## Reset Password Routes
To reset a user's password:
1. Generate a token using the [Generate Reset Password Token API route](#generate-reset-password-token-route).
- The API route emits the `auth.password_reset` event, passing the token in the payload.
- You can create a subscriber, as seen in [this guide](../reset-password/page.mdx), that listens to the event and send a notification to the user.
2. Pass the token to the [Reset Password API route](#reset-password-route) to reset the password.
- The URL in the user's notification should direct them to a frontend URL, which sends a request to this route.
<Note title="Example">
[Storefront Development: How to Reset a Customer's Password.](../../../storefront-development/customers/reset-password/page.mdx)
</Note>
### Generate Reset Password Token Route
The Medusa application defines an API route at `/auth/{actor_type}/{auth_provider}/reset-password` that emits the `auth.password_reset` event, passing the token in the payload.
```bash
curl -X POST http://localhost:9000/auth/{actor_type}/{providers}/reset-password
-H 'Content-Type: application/json' \
--data-raw '{
"identifier": "Whitney_Schultz@gmail.com"
}'
```
<Note>
This API route is useful for providers like `emailpass` that store a user's password and use it for authentication.
</Note>
#### Path Parameters
Its path parameters are:
- `{actor_type}`: the actor type of the user you're authenticating. For example, `customer`.
- `{provider}`: the auth provider to handle the authentication. For example, `emailpass`.
#### Request Body Parameters
This route accepts in the request body an object having the following property:
- `identifier`: The user's identifier in the specified auth provider. For example, for the `emailpass` auth provider, you pass the user's email.
#### Response Fields
If the authentication is successful, the request returns a `201` response code.
### Reset Password Route
The Medusa application defines an API route at `/auth/{actor_type}/{auth_provider}/update` that accepts a token and, if valid, updates the user's password.
```bash
curl -X POST http://localhost:9000/auth/{actor_type}/{providers}/update?token=123
-H 'Content-Type: application/json' \
--data-raw '{
"email": "Whitney_Schultz@gmail.com",
"password": "supersecret"
}'
```
<Note>
This API route is useful for providers like `emailpass` that store a user's password and use it for logging them in.
</Note>
#### Path Parameters
Its path parameters are:
- `{actor_type}`: the actor type of the user you're authenticating. For example, `customer`.
- `{provider}`: the auth provider to handle the authentication. For example, `emailpass`.
#### Query Parameters
The route accepts a `token` query parameter, which is the token generated using the [Generate Reset Password Token route](#generate-reset-password-token-route).
### Request Body Parameters
This route accepts in the request body an object that has the data necessary for the provider to update the user's password.
For the `emailpass` provider, you must pass the following properties:
- `email`: The user's email.
- `password`: The new password.
### Response Fields
If the authentication is successful, the request returns an object with a `success` property set to `true`:
```json
{
"success": "true"
}
```
@@ -0,0 +1,128 @@
import { Prerequisites } from "docs-ui"
export const metadata = {
title: `How to Handle Password Reset Token Event`,
}
# {metadata.title}
In this guide, you'll learn how to handle the `auth.password_reset` event, which is emitted when a request is sent to the [Generate Reset Password Token API route](../authentication-route/page.mdx#generate-reset-password-token-route), to send reset instructions to the user.
<Prerequisites
items={[
{
text: "A notification provider module, such as SendGrid",
link: "/architectural-modules/notification/sendgrid"
}
]}
/>
## 1. Create Subscriber
The first step is to create a subscriber that listens to the `auth.password_reset` and sends the user a notification with instructions to reset their password.
Create the file `src/subscribers/handle-reset.ts` with the following content:
export const highlights=[
["8", "data", "The data payload of the event."],
["9", "entity_id", "The user's identifier, which is the email when using the `emailpass` provider."],
["10", "token", "The password reset token."],
["11", "actor_type", "The user's actor type."],
["19", "urlPrefix", "Set the page's URL based on the user's actor type."],
["21", "createNotifications", "Send a notification to the user."],
["23", `"email"`, "The channel to send the notification through."],
["24", "template", "The template defined in the third-party provider."],
["25", "data", "The data to pass to the template in the third-party provider."],
["27", "url", "The frontend URL to redirect the user to reset their password."]
]
```ts title="src/subscribers/handle-reset.ts" collapsibleLines="1-6" expandMoreLabel="Show Imports"
import {
SubscriberArgs,
type SubscriberConfig,
} from "@medusajs/medusa"
import { Modules } from "@medusajs/framework/utils"
export default async function resetPasswordTokenHandler({
event: { data: {
entity_id: email,
token,
actor_type,
} },
container,
}: SubscriberArgs<{ entity_id: string, token: string, actor_type: string }>) {
const notificationModuleService = container.resolve(
Modules.NOTIFICATION
)
const urlPrefix = actor_type === "customer" ? "https://storefront.com" : "https://admin.com"
await notificationModuleService.createNotifications({
to: email,
channel: "email",
template: "reset-password-template",
data: {
// a URL to a frontend application
url: `${urlPrefix}/reset-password?token=${token}&email=${email}`,
},
})
}
export const config: SubscriberConfig = {
event: "auth.password_reset",
}
```
You subscribe to the `auth.password_reset` event. The event has a data payload object with the following properties:
- `entity_id`: The identifier of the user. When using the `emailpass` provider, it's the user's email.
- `token`: The token to reset the user's password.
- `actor_type`: The user's actor type. For example, if the user is a customer, the `actor_type` is `customer`. If it's an admin user, the `actor_type` is `user`.
In the subscriber, you:
- Decide the frontend URL based on whether the user is a customer or admin user by checking the value of `actor_type`.
- Resolve the Notification Module and use its `createNotifications` method to send the notification.
- You pass to the `createNotifications` method an object having the following properties:
- `to`: The identifier to send the notification to, which in this case is the email.
- `channel`: The channel to send the notification through, which in this case is email.
- `template`: The template ID in the third-party service.
- `data`: The data payload to pass to the template. You pass the URL to redirect the user to. You must pass the token and email in the URL so that the frontend can send them later to the Medusa application when reseting the password.
---
## 2. Test it Out: Generate Reset Password Token
To test the subscriber out, send a request to the `/auth/{actor_type}/{auth_provider}/reset-password` API route, replacing `{actor_type}` and `{auth_provider}` with the user's actor type and provider used for authentication respectively.
For example, to generate a reset password token for an admin user using the `emailpass` provider, send the following request:
```bash
curl --location 'http://localhost:9000/auth/user/emailpass/reset-password' \
--header 'Content-Type: application/json' \
--data-raw '{
"identifier": "admin-test@gmail.com"
}'
```
In the request body, you must pass an `identifier` parameter. Its value is the user's identifier, which is the email in this case.
If the token is generated successfully, the request returns a response with `201` status code. In the terminal, you'll find the following message indicating that the `auth.password_reset` event was emitted and your subscriber ran:
```plain
info: Processing auth.password_reset which has 1 subscribers
```
The notification is sent to the user with the frontend URL to enter a new password.
---
## Next Steps: Implementing Frontend
In your frontend, you must have a page that accepts `token` and `email` query parameters.
The page shows the user password fields to enter their new password, then submits the new password, token, and email to the [Reset Password Route](../authentication-route/page.mdx#reset-password-route).
### Examples
- [Storefront Guide: Reset Customer Password](../../../storefront-development/customers/reset-password/page.mdx)
@@ -0,0 +1,285 @@
import { CodeTabs, CodeTab, Prerequisites } from "docs-ui"
export const metadata = {
title: `Reset Customer Password in Storefront`,
}
# {metadata.title}
Customers reset their password if they forget it.
To implement the flow to reset a customer's password, you need two pages in your storefront:
1. A page to request the password reset.
2. A page that prompts the customer to enter a new password.
---
## 1. Request Reset Password Page
The request password reset page prompts the customer to enter their email. Then, it sends a request to the [Request Reset Password Token API route](!api!/store#auth_postactor_typeauth_providerresetpassword) to send the customer an email with the URL to reset their password.
<Prerequisites
items={[
{
text: "While it's not required, it's recommended to implement the subscriber that sends the customer an email with the URL to reset their password.",
link: "/commerce-modules/auth/reset-password"
}
]}
/>
For example:
<CodeTabs group="store-request">
<CodeTab label="Fetch API" value="fetch">
export const fetchHighlights = [
["5", "email", "Assuming the email is retrieved from an input field."],
["10", "fetch", "Send a request to send the token to the customer."],
["17", "identifier", "Pass the email in the `identifier` request body parameter."]
]
```ts highlights={fetchHighlights}
const handleSubmit = async (
e: React.FormEvent<HTMLFormElement> // or other form event
) => {
e.preventDefault()
if (!email) {
alert("Email is required")
return
}
fetch(`http://localhost:9000/auth/customer/emailpass/reset-password`, {
credentials: "include",
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
identifier: email,
}),
})
.then(() => {
alert("If an account exists with the specified email, it'll receive instructions to reset the password.")
})
}
```
</CodeTab>
<CodeTab label="React" value="react">
export const highlights = [
["19", "fetch", "Send a request to send the token to the customer."],
["26", "identifier", "Pass the email in the `identifier` request body parameter."]
]
```tsx highlights={highlights}
"use client" // include with Next.js 13+
import { useState } from "react"
export default function RequestResetPassword() {
const [loading, setLoading] = useState(false)
const [email, setEmail] = useState("")
const handleSubmit = async (
e: React.FormEvent<HTMLFormElement>
) => {
e.preventDefault()
if (!email) {
alert("Email is required")
return
}
setLoading(true)
fetch(`http://localhost:9000/auth/customer/emailpass/reset-password`, {
credentials: "include",
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
identifier: email,
}),
})
.then(() => {
alert("If an account exists with the specified email, it'll receive instructions to reset the password.")
setLoading(false)
})
}
return (
<form onSubmit={handleSubmit}>
<label>Email</label>
<input
placeholder="Email"
type="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
/>
<button type="submit" disabled={loading}>
Request Password Reset
</button>
</form>
)
}
```
</CodeTab>
</CodeTabs>
In this example, you send a request to `http://localhost:9000/auth/customer/emailpass/reset-password` API route when the form that has the email field is submitted.
In the request body, you pass an `identifier` parameter, which is the customer's email.
<Note title="Tip">
The Request Reset Password Token API route returns a successful response always, even if the customer's email doesn't exist. However, the customer only receives an email if they have an account with that email.
</Note>
---
## 2. Reset Password Page
The reset password page is the URL used in the email sent to the customer. It receives a `token` and `email` query parameters, prompts the customer for a new password, and sends a request to the [Reset Password API route](!api!/store#auth_postactor_typeauth_providerupdate).
<Note>
If you followed [this guide](../../../commerce-modules/auth/reset-password/page.mdx) to set up a subscriber that sends the customer an email, make sure to use the URL of this page in the notification's data payload.
</Note>
For example:
<CodeTabs group="store-request">
<CodeTab label="Fetch API" value="fetch">
export const resetPasswordFetchHighlights = [
["2", "token", "Receive the token from a query parameter."],
["3", "email", "Receive the email from a query parameter."],
["9", "password", "Assuming the password is retrieved from an input field."],
["14", "fetch", "Send a request to update the customer's password."],
["14", "token", "Pass the token as a query parameter."],
["20", "body", "Pass the email and password in the request body."]
]
```ts highlights={resetPasswordFetchHighlights}
const queryParams = new URLSearchParams(window.location.search)
const token = queryParams.get("token")
const email = queryParams.get("email")
const handleSubmit = async (
e: React.FormEvent<HTMLFormElement>
) => {
e.preventDefault()
if (!password) {
alert("Password is required")
return
}
fetch(`http://localhost:9000/auth/customer/emailpass/update?token=${token}`, {
credentials: "include",
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
email,
password,
}),
})
.then((res) => res.json())
.then(({ success }) => {
alert(success ? "Password reset successfully!" : "Couldn't reset password")
})
}
```
</CodeTab>
<CodeTab label="React" value="react">
export const resetPasswordHighlights = [
["18", "token", "Receive the token from a query parameter."],
["21", "email", "Receive the email from a query parameter."],
["35", "fetch", "Send a request to update the customer's password."],
["35", "token", "Pass the token as a query parameter."],
["41", "body", "Pass the email and password in the request body."]
]
```tsx highlights={resetPasswordHighlights}
"use client" // include with Next.js 13+
import { useMemo, useState } from "react"
export default function ResetPassword() {
const [loading, setLoading] = useState(false)
const [password, setPassword] = useState("")
// for other than Next.js
const searchParams = useMemo(() => {
if (typeof window === "undefined") {
return
}
return new URLSearchParams(
window.location.search
)
}, [])
const token = useMemo(() => {
return searchParams?.get("token")
}, [searchParams])
const email = useMemo(() => {
return searchParams?.get("email")
}, [searchParams])
const handleSubmit = async (
e: React.FormEvent<HTMLFormElement>
) => {
e.preventDefault()
if (!password) {
alert("Password is required")
return
}
setLoading(true)
fetch(`http://localhost:9000/auth/customer/emailpass/update?token=${token}`, {
credentials: "include",
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
email,
password,
}),
})
.then((res) => res.json())
.then(({ success }) => {
alert(success ? "Password reset successfully!" : "Couldn't reset password")
setLoading(false)
})
}
return (
<form onSubmit={handleSubmit}>
<label>Password</label>
<input
placeholder="Password"
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
/>
<button type="submit" disabled={loading}>
Reset Password
</button>
</form>
)
}
```
</CodeTab>
</CodeTabs>
In this example, you receive the `token` and `email` from the page's query parameters.
Then, when the form that has the password field is submitted, you send a request to the `http://localhost:9000/auth/customer/emailpass/update` API route. You pass it the token as a query parameter, and the email and password in the request body.
@@ -8,4 +8,6 @@ export const metadata = {
This section of the documentation holds guides to help you build a storefront for your Medusa application.
<ChildDocs />
<ChildDocs onlyTopLevel={true} showItems={["Tips", "Publishable API Key"]} />
<ChildDocs hideItems={["Tips", "Publishable API Key"]} />
+3 -1
View File
@@ -2223,5 +2223,7 @@ export const generatedEditDates = {
"references/user/IMessageAggregator/methods/user.IMessageAggregator.getMessages/page.mdx": "2024-10-03T00:12:20.668Z",
"references/user/interfaces/user.IModuleService/page.mdx": "2024-10-03T00:12:20.657Z",
"references/user/interfaces/user.MessageAggregatorFormat/page.mdx": "2024-10-03T00:12:20.662Z",
"app/troubleshooting/dist-imports/page.mdx": "2024-10-03T09:19:37.639Z"
"app/troubleshooting/dist-imports/page.mdx": "2024-10-03T09:19:37.639Z",
"app/commerce-modules/auth/reset-password/page.mdx": "2024-09-25T09:36:26.592Z",
"app/storefront-development/customers/reset-password/page.mdx": "2024-09-25T10:21:46.647Z"
}
@@ -139,6 +139,10 @@ export const filesMap = [
"filePath": "/www/apps/resources/app/commerce-modules/auth/page.mdx",
"pathname": "/commerce-modules/auth"
},
{
"filePath": "/www/apps/resources/app/commerce-modules/auth/reset-password/page.mdx",
"pathname": "/commerce-modules/auth/reset-password"
},
{
"filePath": "/www/apps/resources/app/commerce-modules/cart/concepts/page.mdx",
"pathname": "/commerce-modules/cart/concepts"
@@ -775,6 +779,10 @@ export const filesMap = [
"filePath": "/www/apps/resources/app/storefront-development/customers/register/page.mdx",
"pathname": "/storefront-development/customers/register"
},
{
"filePath": "/www/apps/resources/app/storefront-development/customers/reset-password/page.mdx",
"pathname": "/storefront-development/customers/reset-password"
},
{
"filePath": "/www/apps/resources/app/storefront-development/customers/retrieve/page.mdx",
"pathname": "/storefront-development/customers/retrieve"
+16
View File
@@ -279,6 +279,14 @@ export const generatedSidebar = [
"title": "Create an Actor Type",
"children": []
},
{
"loaded": true,
"isPathHref": true,
"type": "link",
"path": "/commerce-modules/auth/reset-password",
"title": "Handle Password Reset Event",
"children": []
},
{
"loaded": true,
"isPathHref": true,
@@ -8471,6 +8479,14 @@ export const generatedSidebar = [
"title": "Third-Party (Social) Login",
"children": []
},
{
"loaded": true,
"isPathHref": true,
"type": "link",
"path": "/storefront-development/customers/reset-password",
"title": "Reset Password",
"children": []
},
{
"loaded": true,
"isPathHref": true,
+10
View File
@@ -138,6 +138,11 @@ export const sidebar = sidebarAttachHrefCommonOptions([
path: "/commerce-modules/auth/create-actor-type",
title: "Create an Actor Type",
},
{
type: "link",
path: "/commerce-modules/auth/reset-password",
title: "Handle Password Reset Event",
},
{
type: "link",
path: "/references/auth/provider",
@@ -2034,6 +2039,11 @@ export const sidebar = sidebarAttachHrefCommonOptions([
path: "/storefront-development/customers/third-party-login",
title: "Third-Party (Social) Login",
},
{
type: "link",
path: "/storefront-development/customers/reset-password",
title: "Reset Password",
},
{
type: "link",
path: "/storefront-development/customers/retrieve",
@@ -22,6 +22,9 @@
* type: object
* title: input
* description: The input data necessary for authentication. For example, for email-pass authentication, pass `email` and `password` properties.
* example:
* email: "admin@medusa-test.com"
* password: "supersecret"
* x-codeSamples:
* - lang: Shell
* label: cURL
@@ -0,0 +1,60 @@
/**
* @oas [post] /auth/user/{auth_provider}/reset-password
* operationId: PostActor_typeAuth_providerResetPassword
* summary: Generate Reset Password Token for Admin User
* x-sidebar-summary: Generate Reset Password Token
* description: >
* Generate a reset password token for an admin user. This API route emits the `` event, passing it the token as a payload. You can listen to that event and send the user a notification. The notification should have a URL that accepts a `token` query parameter.
*
*
* Use the generated token to update the user's password using the Reset Password API route.
* externalDocs:
* url: https://docs.medusajs.com/v2/resources/commerce-modules/auth/authentication-route#generate-reset-password-token-route
* description: Learn more about this API route.
* x-authenticated: false
* parameters:
* - name: auth_provider
* in: path
* description: The provider used for authentication.
* required: true
* schema:
* type: string
* example: "emailpass"
* requestBody:
* content:
* application/json:
* schema:
* type: object
* title: identifier
* description: The user's identifier for the selected auth provider. For example, for the `emailpass` auth provider, the value is the user's email.
* example: "admin@medusa-test.com"
* x-codeSamples:
* - lang: Shell
* label: cURL
* source: |-
* curl -X POST '{backend_url}/auth/user/emailpass/reset-password' \
* -H 'Content-Type: application/json' \
* --data-raw '{
* "identifier": "admin@medusa-test.com"
* }'
* tags:
* - Auth
* responses:
* "201":
* description: OK
* "400":
* $ref: "#/components/responses/400_error"
* "401":
* $ref: "#/components/responses/unauthorized"
* "404":
* $ref: "#/components/responses/not_found_error"
* "409":
* $ref: "#/components/responses/invalid_state_error"
* "422":
* $ref: "#/components/responses/invalid_request_error"
* "500":
* $ref: "#/components/responses/500_error"
* x-workflow: generateResetPasswordTokenWorkflow
*
*/
@@ -0,0 +1,76 @@
/**
* @oas [post] /auth/user/{auth_provider}/update
* operationId: PostActor_typeAuth_providerUpdate
* summary: Reset an Admin User's Password
* x-sidebar-summary: Reset Password
* description: Reset a user's password. Generate the reset password token first using the Get Reset Password Token API route.
* externalDocs:
* url: https://docs.medusajs.com/v2/resources/commerce-modules/auth/authentication-route#reset-password-route
* description: Learn more about this API route.
* x-authenticated: false
* parameters:
* - name: auth_provider
* in: path
* description: The provider used for authentication.
* required: true
* schema:
* type: string
* example: "emailpass"
* - name: token
* in: query
* description: The reset password token received using the Get Reset Password API route.
* required: true
* schema:
* type: string
* requestBody:
* content:
* application/json:
* schema:
* type: object
* title: input
* description: The input data necessary for authentication. For example, for email-pass authentication, pass `email` and `password` properties.
* example:
* email: "admin@medusa-test.com"
* password: "supersecret"
* x-codeSamples:
* - lang: Shell
* label: cURL
* source: |-
* curl -X POST '{backend_url}/auth/user/emailpass/update?token=123' \
* -H 'Content-Type: application/json' \
* --data-raw '{
* "email": "admin@medusa-test.com",
* "password": "supersecret"
* }'
* tags:
* - Auth
* responses:
* "200":
* description: OK
* content:
* application/json:
* schema:
* type: object
* required:
* - success
* description: Details on the reset password's status.
* properties:
* success:
* type: boolean
* title: success
* description: Whether the password was reset successfully.
* "400":
* $ref: "#/components/responses/400_error"
* "401":
* $ref: "#/components/responses/unauthorized"
* "404":
* $ref: "#/components/responses/not_found_error"
* "409":
* $ref: "#/components/responses/invalid_state_error"
* "422":
* $ref: "#/components/responses/invalid_request_error"
* "500":
* $ref: "#/components/responses/500_error"
*
*/
@@ -9,8 +9,8 @@
* When used with a third-party provider, such as Google, the request returns a `location` property. You redirect to the
* specified URL in your storefront to continue authentication with the third-party service.
* externalDocs:
* url: https://docs.medusajs.com/v2/resources/commerce-modules/auth/authentication-route#types-of-authentication-flows
* description: Learn about different authentication flows.
* url: https://docs.medusajs.com/v2/storefront-development/customers/login#1-using-a-jwt-token
* description: "Storefront development: How to login as a customer"
* x-authenticated: false
* parameters:
* - name: auth_provider
@@ -12,8 +12,8 @@
* You can decode the JWT token using libraries like [react-jwt](https://www.npmjs.com/package/react-jwt) in the storefront. If the decoded data doesn't
* have an `actor_id` property, then you must register the customer using the Create Customer API route passing the token in the request's Authorization header.
* externalDocs:
* url: https://docs.medusajs.com/v2/resources/commerce-modules/auth/authentication-route#2-third-party-service-authenticate-flow
* description: Learn about third-party authentication flow.
* url: https://docs.medusajs.com/v2/storefront-development/customers/third-party-login
* description: "Storefront development: Implement third-party (social) login."
* x-authenticated: false
* parameters:
* - name: auth_provider
@@ -4,8 +4,8 @@
* summary: Retrieve Registration JWT Token
* description: This API route retrieves a registration JWT token of a customer that hasn't been registered yet. The token is used in the header of requests that create a customer.
* externalDocs:
* url: https://docs.medusajs.com/v2/resources/commerce-modules/auth/authentication-route#1-basic-authentication-flow
* description: Learn about the basic authentication flow.
* url: https://docs.medusajs.com/v2/storefront-development/customers/register
* description: "Storefront development: How to register a customer"
* x-authenticated: false
* parameters:
* - name: auth_provider
@@ -22,6 +22,9 @@
* type: object
* title: input
* description: The input data necessary for authentication. For example, for email-pass authentication, pass `email` and `password` properties.
* example:
* email: "customer@gmail.com"
* password: "supersecret"
* x-codeSamples:
* - lang: Shell
* label: cURL
@@ -0,0 +1,60 @@
/**
* @oas [post] /auth/customer/{auth_provider}/reset-password
* operationId: PostActor_typeAuth_providerResetPassword
* summary: Generate Reset Password Token for Customer
* x-sidebar-summary: Generate Reset Password Token
* description: >
* Generate a reset password token for a customer. This API route emits the `auth.password_reset` event, passing it the token as a payload. You can listen to that event and send the user a notification. The notification should have a URL that accepts a `token` query parameter.
*
*
* Use the generated token to update the user's password using the Reset Password API route.
* externalDocs:
* url: https://docs.medusajs.com/v2/resources/storefront-development/customers/reset-password#1-request-reset-password-page
* description: "Storefront development: How to create the request reset password page."
* x-authenticated: false
* parameters:
* - name: auth_provider
* in: path
* description: The provider used for authentication.
* required: true
* schema:
* type: string
* example: "emailpass"
* requestBody:
* content:
* application/json:
* schema:
* type: object
* title: identifier
* description: The customer's identifier for the selected auth provider. For example, for the `emailpass` auth provider, the value is the customer's email.
* example: "customer@gmail.com"
* x-codeSamples:
* - lang: Shell
* label: cURL
* source: |-
* curl -X POST '{backend_url}/auth/customer/emailpass/reset-password' \
* -H 'Content-Type: application/json' \
* --data-raw '{
* "identifier": "customer@gmail.com"
* }'
* tags:
* - Auth
* responses:
* "201":
* description: OK
* "400":
* $ref: "#/components/responses/400_error"
* "401":
* $ref: "#/components/responses/unauthorized"
* "404":
* $ref: "#/components/responses/not_found_error"
* "409":
* $ref: "#/components/responses/invalid_state_error"
* "422":
* $ref: "#/components/responses/invalid_request_error"
* "500":
* $ref: "#/components/responses/500_error"
* x-workflow: generateResetPasswordTokenWorkflow
*
*/
@@ -0,0 +1,76 @@
/**
* @oas [post] /auth/customer/{auth_provider}/update
* operationId: PostActor_typeAuth_providerUpdate
* summary: Reset a Customer's Password
* x-sidebar-summary: Reset Password
* description: Reset a customer's password. Generate the reset password token first using the Get Reset Password Token API route.
* externalDocs:
* url: https://docs.medusajs.com/v2/resources/storefront-development/customers/reset-password#2-reset-password-page
* description: "Storefront development: How to create the reset password page."
* x-authenticated: false
* parameters:
* - name: auth_provider
* in: path
* description: The provider used for authentication.
* required: true
* schema:
* type: string
* example: "emailpass"
* - name: token
* in: query
* description: The reset password token received using the Get Reset Password API route.
* required: true
* schema:
* type: string
* requestBody:
* content:
* application/json:
* schema:
* type: object
* title: input
* description: The input data necessary for authentication with the specified auth provider. For example, for email-pass authentication, pass `email` and `password` properties.
* example:
* email: "customer@gmail.com"
* password: "supersecret"
* x-codeSamples:
* - lang: Shell
* label: cURL
* source: |-
* curl -X POST '{backend_url}/auth/customer/emailpass/update?token=123' \
* -H 'Content-Type: application/json' \
* --data-raw '{
* "email": "customer@gmail.com",
* "password": "supersecret"
* }'
* tags:
* - Auth
* responses:
* "200":
* description: OK
* content:
* application/json:
* schema:
* type: object
* required:
* - success
* description: Details on the reset password's status.
* properties:
* success:
* type: boolean
* title: success
* description: Whether the password was reset successfully.
* "400":
* $ref: "#/components/responses/400_error"
* "401":
* $ref: "#/components/responses/unauthorized"
* "404":
* $ref: "#/components/responses/not_found_error"
* "409":
* $ref: "#/components/responses/invalid_state_error"
* "422":
* $ref: "#/components/responses/invalid_request_error"
* "500":
* $ref: "#/components/responses/500_error"
*
*/
@@ -4,6 +4,9 @@
* summary: Set Authentication Session
* description: Set the cookie session ID of a customer. The customer must be previously authenticated with the `/auth/customer/{provider}` API route first,
* as the JWT token is required in the header of the request.
* externalDocs:
* url: https://docs.medusajs.com/v2/storefront-development/customers/login#2-using-a-cookie-session
* description: "Storefront development: How to login as a customer"
* x-authenticated: true
* x-codeSamples:
* - lang: Shell
@@ -4,8 +4,8 @@
* summary: Refresh Authentication Token
* description: Refresh the authentication token of a customer. This is useful after authenticating a customer with a third-party service to ensure the token holds the new user's details, or when you don't want customers to re-login every day.
* externalDocs:
* url: https://docs.medusajs.com/v2/resources/commerce-modules/auth/authentication-route#2-third-party-service-authenticate-flow
* description: Learn about third-party authentication flow.
* url: https://docs.medusajs.com/v2/storefront-development/customers/third-party-login
* description: "Storefront development: Implement third-party (social) login."
* x-authenticated: true
* x-codeSamples:
* - lang: Shell