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
@@ -45,7 +45,9 @@ export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
await service.validateCallback(auth_provider, authData)
const entityIdKey = `${actor_type}_id`
const entityId = authIdentity.app_metadata?.[entityIdKey]
const entityId = authIdentity?.app_metadata?.[entityIdKey] as
| string
| undefined
if (success) {
const { http } = req.scope.resolve(
ContainerRegistrationKeys.CONFIG_MODULE
@@ -54,9 +56,9 @@ export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
const { jwtSecret, jwtExpiresIn } = http
const token = generateJwtToken(
{
actor_id: entityId,
actor_id: entityId ?? "",
actor_type,
auth_identity_id: authIdentity.id,
auth_identity_id: authIdentity?.id ?? "",
app_metadata: {
[entityIdKey]: entityId,
},
@@ -57,14 +57,16 @@ export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
).projectConfig
const entityIdKey = `${actor_type}_id`
const entityId = authIdentity.app_metadata?.[entityIdKey]
const entityId = authIdentity?.app_metadata?.[entityIdKey] as
| string
| undefined
const { jwtSecret, jwtExpiresIn } = http
const token = generateJwtToken(
{
actor_id: entityId,
actor_id: entityId ?? "",
actor_type,
auth_identity_id: authIdentity.id,
auth_identity_id: authIdentity?.id ?? "",
app_metadata: {
[entityIdKey]: entityId,
},