Skip to content

Commit

Permalink
fix: Remove the endpoint to create a user (#8629)
Browse files Browse the repository at this point in the history
  • Loading branch information
sradevski committed Aug 16, 2024
1 parent 5200e81 commit 0f24013
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 48 deletions.
3 changes: 2 additions & 1 deletion integration-tests/http/__tests__/auth/admin/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ medusaIntegrationTestRunner({
await createAdminUser(dbConnection, adminHeaders, getContainer())
})

it.only("test the entire authentication flow", async () => {
// TODO: This test won't work since we don't allow creating a user through HTTP. We need to have the invite flow plugged in here.
it.skip("test the entire authentication flow", async () => {
// BREAKING: `/admin/auth` changes to `/auth/user/emailpass`
const signup = await api.post("/auth/user/emailpass", {
email: "newadmin@medusa.js",
Expand Down
13 changes: 0 additions & 13 deletions packages/medusa/src/api/admin/users/middlewares.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as QueryConfig from "./query-config"

import {
AdminCreateUser,
AdminGetUserParams,
AdminGetUsersParams,
AdminUpdateUser,
Expand All @@ -26,18 +25,6 @@ export const adminUserRoutesMiddlewares: MiddlewareRoute[] = [
),
],
},
{
method: ["POST"],
matcher: "/admin/users",
middlewares: [
authenticate("user", ["bearer", "session"], { allowUnregistered: true }),
validateAndTransformBody(AdminCreateUser),
validateAndTransformQuery(
AdminGetUserParams,
QueryConfig.retrieveTransformQueryConfig
),
],
},
{
method: ["GET"],
matcher: "/admin/users/:id",
Expand Down
35 changes: 1 addition & 34 deletions packages/medusa/src/api/admin/users/route.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { createUserAccountWorkflow } from "@medusajs/core-flows"
import { CreateUserDTO, HttpTypes } from "@medusajs/types"
import { HttpTypes } from "@medusajs/types"
import {
ContainerRegistrationKeys,
MedusaError,
remoteQueryObjectFromString,
} from "@medusajs/utils"
import {
AuthenticatedMedusaRequest,
MedusaResponse,
} from "../../../types/routing"
import { refetchUser } from "./helpers"

export const GET = async (
req: AuthenticatedMedusaRequest,
Expand All @@ -35,34 +32,4 @@ export const GET = async (
})
}

export const POST = async (
req: AuthenticatedMedusaRequest<CreateUserDTO>,
res: MedusaResponse<HttpTypes.AdminUserResponse>
) => {
// If `actor_id` is present, the request carries authentication for an existing user
if (req.auth_context.actor_id) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
"Request carries authentication for an existing user"
)
}

const input = {
input: {
userData: req.validatedBody,
authIdentityId: req.auth_context.auth_identity_id,
},
}

const { result } = await createUserAccountWorkflow(req.scope).run(input)

const user = await refetchUser(
result.id,
req.scope,
req.remoteQueryConfig.fields
)

res.status(200).json({ user })
}

export const AUTHENTICATE = false

0 comments on commit 0f24013

Please sign in to comment.