Files
medusa-store/integration-tests/plugins/helpers/create-authenticated-customer.ts
Philip Korsholm e2738ab91d feat(auth): Make token auth default (#6305)
**What**
- make token auth the default being returned from authentication endpoints in api-v2
- Add `auth/session` to convert token to session based auth
- add regex-scopes to authenticate middleware 

Co-authored-by: Sebastian Rindom <7554214+srindom@users.noreply.github.com>
2024-02-05 08:17:08 +00:00

27 lines
683 B
TypeScript

import { IAuthModuleService, ICustomerModuleService } from "@medusajs/types"
import jwt from "jsonwebtoken"
export const createAuthenticatedCustomer = async (
customerModuleService: ICustomerModuleService,
authService: IAuthModuleService,
jwtSecret: string
) => {
const customer = await customerModuleService.create({
first_name: "John",
last_name: "Doe",
email: "john@me.com",
})
const authUser = await authService.createAuthUser({
entity_id: "store_user",
provider: "emailpass",
scope: "store",
app_metadata: { customer_id: customer.id },
})
const token = jwt.sign(authUser, jwtSecret)
return { customer, authUser, jwt: token }
}