Revamp auth module to support multiple providers linked to a single auth identity (#7521)
This commit is contained in:
+24
-8
@@ -158,8 +158,12 @@ describe("Google auth provider", () => {
|
||||
}),
|
||||
create: jest.fn().mockImplementation(() => {
|
||||
return {
|
||||
entity_id: "test@admin.com",
|
||||
provider: "google",
|
||||
provider_identities: [
|
||||
{
|
||||
entity_id: "test@admin.com",
|
||||
provider: "google",
|
||||
},
|
||||
],
|
||||
}
|
||||
}),
|
||||
}
|
||||
@@ -177,8 +181,12 @@ describe("Google auth provider", () => {
|
||||
success: true,
|
||||
successRedirectUrl: baseUrl,
|
||||
authIdentity: {
|
||||
entity_id: "test@admin.com",
|
||||
provider: "google",
|
||||
provider_identities: [
|
||||
{
|
||||
entity_id: "test@admin.com",
|
||||
provider: "google",
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
})
|
||||
@@ -187,8 +195,12 @@ describe("Google auth provider", () => {
|
||||
const authServiceSpies = {
|
||||
retrieve: jest.fn().mockImplementation(() => {
|
||||
return {
|
||||
entity_id: "test@admin.com",
|
||||
provider: "google",
|
||||
provider_identities: [
|
||||
{
|
||||
entity_id: "test@admin.com",
|
||||
provider: "google",
|
||||
},
|
||||
],
|
||||
}
|
||||
}),
|
||||
create: jest.fn().mockImplementation(() => {
|
||||
@@ -209,8 +221,12 @@ describe("Google auth provider", () => {
|
||||
success: true,
|
||||
successRedirectUrl: baseUrl,
|
||||
authIdentity: {
|
||||
entity_id: "test@admin.com",
|
||||
provider: "google",
|
||||
provider_identities: [
|
||||
{
|
||||
entity_id: "test@admin.com",
|
||||
provider: "google",
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
@@ -130,13 +130,11 @@ export class GoogleAuthService extends AbstractAuthModuleProvider {
|
||||
try {
|
||||
authIdentity = await authIdentityService.retrieve({
|
||||
entity_id,
|
||||
provider: this.provider,
|
||||
})
|
||||
} catch (error) {
|
||||
if (error.type === MedusaError.Types.NOT_FOUND) {
|
||||
const createdAuthIdentity = await authIdentityService.create({
|
||||
entity_id,
|
||||
provider: this.provider,
|
||||
user_metadata: userMetadata,
|
||||
})
|
||||
authIdentity = createdAuthIdentity
|
||||
|
||||
Reference in New Issue
Block a user