|
1
|
import { CreateCustomerDTO } from "@medusajs/types" |
|
2
|
|
|
3
|
export const createAuthenticatedCustomer = async ( |
|
4
|
api: any, |
|
5
|
storeHeaders: Record<any, any>, |
|
6
|
customerData: Partial<CreateCustomerDTO> = {} |
|
7
|
) => { |
|
8
|
const email = customerData.email ?? "tony@start.com" |
|
9
|
const signup = await api.post("/auth/customer/emailpass/register", { |
|
10
|
email, |
|
11
|
password: "secret_password", |
|
12
|
}) |
|
13
|
|
|
14
|
const { |
|
15
|
data: { customer }, |
|
16
|
} = await api.post( |
|
17
|
"/store/customers", |
|
18
|
{ |
|
19
|
email, |
|
20
|
first_name: "John", |
|
21
|
last_name: "Doe", |
|
22
|
metadata: {}, |
|
23
|
...customerData, |
|
24
|
}, |
|
25
|
{ |
|
26
|
headers: { |
|
27
|
authorization: `Bearer ${signup.data.token}`, |
|
28
|
...storeHeaders.headers, |
|
29
|
}, |
|
30
|
} |
|
31
|
) |
|
32
|
|
|
33
|
const signin = await api.post("/auth/customer/emailpass", { |
|
34
|
email, |
|
35
|
password: "secret_password", |
|
36
|
}) |
|
37
|
|
|
38
|
return { customer, jwt: signin.data.token } |
|
39
|
} |