Skip to content

Commit

Permalink
Feat(auth): Remove auth provider entity (#6314)
Browse files Browse the repository at this point in the history
**What**
- remove auth provider entity

**Why**
- The auth provider entity was not really used anywhere

**How**
- Keeping loader behavior as is but removing the 

Co-authored-by: Sebastian Rindom <7554214+srindom@users.noreply.github.com>
  • Loading branch information
pKorsholm and srindom authored Feb 6, 2024
1 parent b2eaac8 commit 882aa54
Show file tree
Hide file tree
Showing 37 changed files with 178 additions and 1,222 deletions.
5 changes: 5 additions & 0 deletions .changeset/smooth-penguins-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/utils": patch
---

feat(utils): return array or single entity based on input for modules created by internal module service factory
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,7 @@ describe("POST /store/customers/me/addresses", () => {
})

it("should create a customer address", async () => {
const { jwt_secret } = appContainer.resolve("configModule").projectConfig
const { customer, jwt } = await createAuthenticatedCustomer(
customerModuleService,
appContainer.resolve(ModuleRegistrationName.AUTH),
jwt_secret
)
const { customer, jwt } = await createAuthenticatedCustomer(appContainer)

const api = useApi() as any
const response = await api.post(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe("POST /store/customers", () => {
ModuleRegistrationName.AUTH
)
const { jwt_secret } = appContainer.resolve("configModule").projectConfig
const authUser = await authService.createAuthUser({
const authUser = await authService.create({
entity_id: "store_user",
provider: "emailpass",
scope: "store",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { useApi } from "../../../../environment-helpers/use-api"

const env = { MEDUSA_FF_MEDUSA_V2: true }

jest.setTimeout(50000)

describe("DELETE /store/customers/me/addresses/:address_id", () => {
let dbConnection
let appContainer
Expand All @@ -26,14 +28,6 @@ describe("DELETE /store/customers/me/addresses/:address_id", () => {
)
})

// TODO: delete with removal of authProvider
beforeEach(async () => {
const onStart =
appContainer.resolve(ModuleRegistrationName.AUTH).__hooks
.onApplicationStart ?? (() => Promise.resolve())
await onStart()
})

afterAll(async () => {
const db = useDb()
await db.shutdown()
Expand All @@ -46,12 +40,7 @@ describe("DELETE /store/customers/me/addresses/:address_id", () => {
})

it("should delete a customer address", async () => {
const { jwt_secret } = appContainer.resolve("configModule").projectConfig
const { customer, jwt } = await createAuthenticatedCustomer(
customerModuleService,
appContainer.resolve(ModuleRegistrationName.AUTH),
jwt_secret
)
const { customer, jwt } = await createAuthenticatedCustomer(appContainer)

const address = await customerModuleService.addAddresses({
customer_id: customer.id,
Expand All @@ -76,12 +65,7 @@ describe("DELETE /store/customers/me/addresses/:address_id", () => {
})

it("should fail to delete another customer's address", async () => {
const { jwt_secret } = appContainer.resolve("configModule").projectConfig
const { jwt } = await createAuthenticatedCustomer(
customerModuleService,
appContainer.resolve(ModuleRegistrationName.AUTH),
jwt_secret
)
const { jwt } = await createAuthenticatedCustomer(appContainer)

const otherCustomer = await customerModuleService.create({
first_name: "Jane",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { initDb, useDb } from "../../../../environment-helpers/use-db"
import { ICustomerModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { createAuthenticatedCustomer } from "../../../helpers/create-authenticated-customer"
import customer from "../../../../development/database/customer"
import { getContainer } from "../../../../environment-helpers/use-container"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
Expand Down Expand Up @@ -41,12 +40,7 @@ describe("GET /store/customers", () => {
})

it("should retrieve auth user's customer", async () => {
const { jwt_secret } = appContainer.resolve("configModule").projectConfig
const { customer, jwt } = await createAuthenticatedCustomer(
customerModuleService,
appContainer.resolve(ModuleRegistrationName.AUTH),
jwt_secret
)
const { customer, jwt } = await createAuthenticatedCustomer(appContainer)

const api = useApi() as any
const response = await api.get(`/store/customers/me`, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,7 @@ describe("GET /store/customers/me/addresses", () => {
})

it("should get all customer addresses and its count", async () => {
const { jwt_secret } = appContainer.resolve("configModule").projectConfig
const { customer, jwt } = await createAuthenticatedCustomer(
customerModuleService,
appContainer.resolve(ModuleRegistrationName.AUTH),
jwt_secret
)
const { customer, jwt } = await createAuthenticatedCustomer(appContainer)

await customerModuleService.addAddresses([
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ describe("POST /store/customers/:id/addresses/:address_id", () => {
)
})

// TODO: delete with removal of authProvider
beforeEach(async () => {
const onStart =
appContainer.resolve(ModuleRegistrationName.AUTH).__hooks
.onApplicationStart ?? (() => Promise.resolve())
await onStart()
})

afterAll(async () => {
const db = useDb()
await db.shutdown()
Expand All @@ -46,13 +38,7 @@ describe("POST /store/customers/:id/addresses/:address_id", () => {
})

it("should update a customer address", async () => {
const { jwt_secret } = appContainer.resolve("configModule").projectConfig

const { customer, jwt } = await createAuthenticatedCustomer(
customerModuleService,
appContainer.resolve(ModuleRegistrationName.AUTH),
jwt_secret
)
const { customer, jwt } = await createAuthenticatedCustomer(appContainer)

const address = await customerModuleService.addAddresses({
customer_id: customer.id,
Expand Down Expand Up @@ -81,13 +67,7 @@ describe("POST /store/customers/:id/addresses/:address_id", () => {
})

it("should fail to update another customer's address", async () => {
const { jwt_secret } = appContainer.resolve("configModule").projectConfig

const { jwt } = await createAuthenticatedCustomer(
customerModuleService,
appContainer.resolve(ModuleRegistrationName.AUTH),
jwt_secret
)
const { jwt } = await createAuthenticatedCustomer(appContainer)

const otherCustomer = await customerModuleService.create({
first_name: "Jane",
Expand Down
19 changes: 13 additions & 6 deletions integration-tests/plugins/helpers/create-authenticated-customer.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
import { IAuthModuleService, ICustomerModuleService } from "@medusajs/types"
import { CreateCustomerDTO, MedusaContainer } from "@medusajs/types"

import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import jwt from "jsonwebtoken"

export const createAuthenticatedCustomer = async (
customerModuleService: ICustomerModuleService,
authService: IAuthModuleService,
jwtSecret: string
appContainer: MedusaContainer,
customerData: Partial<CreateCustomerDTO> = {}
) => {
const { jwt_secret } = appContainer.resolve("configModule").projectConfig
const authService = appContainer.resolve(ModuleRegistrationName.AUTH)
const customerModuleService = appContainer.resolve(
ModuleRegistrationName.CUSTOMER
)

const customer = await customerModuleService.create({
first_name: "John",
last_name: "Doe",
email: "john@me.com",
...customerData,
})

const authUser = await authService.createAuthUser({
const authUser = await authService.create({
entity_id: "store_user",
provider: "emailpass",
scope: "store",
app_metadata: { customer_id: customer.id },
})

const token = jwt.sign(authUser, jwtSecret)
const token = jwt.sign(authUser, jwt_secret)

return { customer, authUser, jwt: token }
}

This file was deleted.

Loading

0 comments on commit 882aa54

Please sign in to comment.