Files
medusa-store/integration-tests/modules/helpers/create-authenticated-customer.ts
Adrien de Peretti 48963f55ef Chore/rm main entity concept (#7709)
**What**
Update the `MedusaService` class, factory and types to remove the concept of main modules. The idea being that all method will be explicitly named and suffixes to represent the object you are trying to manipulate.
This pr also includes various fixes in different modules

Co-authored-by: Stevche Radevski <4820812+sradevski@users.noreply.github.com>
Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
2024-06-19 13:02:16 +00:00

46 lines
1.1 KiB
TypeScript

import { CreateCustomerDTO, MedusaContainer } from "@medusajs/types"
import { ModuleRegistrationName, Modules } from "@medusajs/modules-sdk"
import jwt from "jsonwebtoken"
export const createAuthenticatedCustomer = async (
appContainer: MedusaContainer,
customerData: Partial<CreateCustomerDTO> = {}
) => {
const { http } = appContainer.resolve("configModule").projectConfig
const authService = appContainer.resolve(ModuleRegistrationName.AUTH)
const customerModuleService = appContainer.resolve(
ModuleRegistrationName.CUSTOMER
)
const customer = await customerModuleService.createCustomers({
first_name: "John",
last_name: "Doe",
email: "john@me.com",
...customerData,
})
const authIdentity = await authService.createAuthIdentities({
provider_identities: [
{
entity_id: "store_user",
provider: "emailpass",
},
],
app_metadata: {
customer_id: customer.id,
},
})
const token = jwt.sign(
{
actor_id: customer.id,
actor_type: "customer",
auth_identity_id: authIdentity.id,
},
http.jwtSecret
)
return { customer, authIdentity, jwt: token }
}