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

This commit is contained in:
Stevche Radevski authored and GitHub committed 2024-06-05 07:47:16 +00:00
1 parent 20cd6a7b51
commit fafc92b875
23 files changed
+640 -216

No files matched your search

@@ -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,
},
+2 -1
View File
@@ -56,8 +56,9 @@ export default async function ({
process.exit(1)
}
// We know the authIdentity is not undefined
await authService.update({
id: authIdentity.id,
id: authIdentity!.id,
app_metadata: {
user_id: user.id,
},