Revamp auth module to support multiple providers linked to a single auth identity (#7521)

This commit is contained in:
Stevche Radevski
2024-06-05 07:47:16 +00:00
committed by GitHub
parent 20cd6a7b51
commit fafc92b875
23 changed files with 640 additions and 216 deletions
@@ -1,34 +1,36 @@
import { IAuthModuleService } from "@medusajs/types"
import { AuthIdentity } from "@models"
import { SqlEntityManager } from "@mikro-orm/postgresql"
export async function createAuthIdentities(
manager: SqlEntityManager,
service: IAuthModuleService,
userData: any[] = [
{
id: "test-id",
entity_id: "test-id",
provider: "manual",
provider_identities: [
{
entity_id: "test-id",
provider: "manual",
},
],
},
{
id: "test-id-1",
entity_id: "test-id-1",
provider: "manual",
provider_identities: [
{
entity_id: "test-id-1",
provider: "manual",
},
],
},
{
entity_id: "test-id-2",
provider: "store",
provider_identities: [
{
entity_id: "test-id-2",
provider: "store",
},
],
},
]
): Promise<AuthIdentity[]> {
const authIdentities: AuthIdentity[] = []
for (const user of userData) {
const authIdentity = manager.create(AuthIdentity, user)
authIdentities.push(authIdentity)
}
await manager.persistAndFlush(authIdentities)
return authIdentities
return await service.create(userData)
}