fix: Update auth app_metadata when deleting users + customers (#9041)

* wip

* more work

* working on stuff

* more

* fix test

* remove incorrect test

* fix test

* fix: Only allow deletion of yourself

* remove redundant tests
This commit is contained in:
Oli Juhl
2024-09-10 19:58:16 +02:00
committed by GitHub
parent e9e0267aa8
commit 4bf42f7889
14 changed files with 322 additions and 183 deletions

View File

@@ -1,6 +1,7 @@
import { IAuthModuleService, IUserModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
import jwt from "jsonwebtoken"
import Scrypt from "scrypt-kdf"
import { getContainer } from "../environment-helpers/use-container"
export const adminHeaders = {
@@ -26,13 +27,16 @@ export const createAdminUser = async (
email: "admin@medusa.js",
})
const hashConfig = { logN: 15, r: 8, p: 1 }
const passwordHash = await Scrypt.kdf("somepassword", hashConfig)
const authIdentity = await authModule.createAuthIdentities({
provider_identities: [
{
provider: "emailpass",
entity_id: "admin@medusa.js",
provider_metadata: {
password: "somepassword",
password: passwordHash.toString("base64"),
},
},
],
@@ -55,5 +59,5 @@ export const createAdminUser = async (
adminHeaders.headers["authorization"] = `Bearer ${token}`
return { user }
return { user, authIdentity }
}