Files
medusa-store/integration-tests/plugins/helpers/create-admin-user.ts
Philip Korsholm f6d38163bb Feat(medusa, user, core-flows): User creation with invites (#6413)
**What**
- add accept invite endpoint 

**Invite accept flow**
- authenticate using the auth endpoint to create and auth-user
- invoke accept endpoint with token and info to create user
2024-02-19 05:29:15 +00:00

26 lines
809 B
TypeScript

import { IAuthModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import adminSeeder from "../../helpers/admin-seeder"
import jwt from "jsonwebtoken"
import { getContainer } from "../../environment-helpers/use-container"
export const createAdminUser = async (dbConnection, adminHeaders) => {
await adminSeeder(dbConnection)
const appContainer = getContainer()!
const authModule: IAuthModuleService = appContainer.resolve(
ModuleRegistrationName.AUTH
)
const authUser = await authModule.create({
provider: "emailpass",
entity_id: "admin@medusa.js",
scope: "admin",
app_metadata: {
user_id: "admin_user",
},
})
const token = jwt.sign(authUser, "test")
adminHeaders.headers["authorization"] = `Bearer ${token}`
}