Browse Source

feat: sync delete authing user before delete _User

MetaPunkGames 7 months ago
parent
commit
2b1d787a7f
1 changed files with 11 additions and 2 deletions
  1. 11 2
      server/cloud/authing/trigger-user-save.js

+ 11 - 2
server/cloud/authing/trigger-user-save.js

@@ -55,6 +55,16 @@ export function defineUserBeforeSave(){
         // console.log(user.toJSON());
         // console.log(user?.get("password"))
         let authingUserExists = await findUserByMobileEmailUserName(user)
+        if(authingUserExists?.statusCode==200){
+            let existsUser = authingUserExists?.data;
+            let deleteRes = await managementClient.deleteUsersBatch({
+                // 替换用户 ID 数组
+                userIds: [existsUser.userId],
+                options: {
+                  userIdType: "user_id"
+                }
+            });
+        }
       });
 }
 /**
@@ -156,8 +166,7 @@ async function syncUserProfileToAuthing(user,profile){
     let authingUserExists = await findUserByMobileEmailUserName(user)
     if(authingUserExists?.statusCode==200){
         let existsUser = authingUserExists?.data;
-    userInfo.userId = existsUser.userId
-
+        userInfo.userId = existsUser.userId
     }
     delete userInfo.objectId
     userInfo.identifyStatus = userInfo.accountState