Revamp auth module to support multiple providers linked to a single auth identity (#7521)
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user