Feat(auth): Remove auth provider entity (#6314)
**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>
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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
|
||||
@@ -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()
|
||||
@@ -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,
|
||||
@@ -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",
|
||||
|
||||
@@ -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"
|
||||
@@ -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`, {
|
||||
|
||||
@@ -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([
|
||||
{
|
||||
|
||||
@@ -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()
|
||||
@@ -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,
|
||||
@@ -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",
|
||||
|
||||
@@ -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 }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user