feat: Revert to using app_metadata for authentication (#7433)

This commit is contained in:
Stevche Radevski
2024-05-23 22:01:41 +02:00
committed by GitHub
parent 6ec6e2c7b6
commit 135772b27b
24 changed files with 149 additions and 265 deletions
+4 -16
View File
@@ -1,8 +1,7 @@
import { ModuleRegistrationName, Modules } from "@medusajs/modules-sdk"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { IAuthModuleService, IUserModuleService } from "@medusajs/types"
import jwt from "jsonwebtoken"
import { getContainer } from "../environment-helpers/use-container"
import { ContainerRegistrationKeys } from "@medusajs/utils"
export const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" },
@@ -21,8 +20,6 @@ export const createAdminUser = async (
const authModule: IAuthModuleService = appContainer.resolve(
ModuleRegistrationName.AUTH
)
const remoteLink = appContainer.resolve(ContainerRegistrationKeys.REMOTE_LINK)
const user = await userModule.create({
first_name: "Admin",
last_name: "User",
@@ -35,19 +32,10 @@ export const createAdminUser = async (
provider_metadata: {
password: "somepassword",
},
})
// Ideally we simulate a signup process than manually linking here.
await remoteLink.create([
{
[Modules.USER]: {
user_id: user.id,
},
[Modules.AUTH]: {
auth_identity_id: authIdentity.id,
},
app_metadata: {
user_id: user.id,
},
])
})
const token = jwt.sign(
{
@@ -2,7 +2,6 @@ import { CreateCustomerDTO, MedusaContainer } from "@medusajs/types"
import { ModuleRegistrationName, Modules } from "@medusajs/modules-sdk"
import jwt from "jsonwebtoken"
import { ContainerRegistrationKeys } from "@medusajs/utils"
export const createAuthenticatedCustomer = async (
appContainer: MedusaContainer,
@@ -13,7 +12,6 @@ export const createAuthenticatedCustomer = async (
const customerModuleService = appContainer.resolve(
ModuleRegistrationName.CUSTOMER
)
const remoteLink = appContainer.resolve(ContainerRegistrationKeys.REMOTE_LINK)
const customer = await customerModuleService.create({
first_name: "John",
@@ -25,19 +23,10 @@ export const createAuthenticatedCustomer = async (
const authIdentity = await authService.create({
entity_id: "store_user",
provider: "emailpass",
})
// Ideally we simulate a signup process than manually linking here.
await remoteLink.create([
{
[Modules.CUSTOMER]: {
customer_id: customer.id,
},
[Modules.AUTH]: {
auth_identity_id: authIdentity.id,
},
app_metadata: {
customer_id: customer.id,
},
])
})
const token = jwt.sign(
{