@@ -1046,21 +1046,29 @@ func (am *DefaultAccountManager) addNewUserToDomainAccount(ctx context.Context,
1046
1046
unlockAccount := am .Store .AcquireWriteLockByUID (ctx , domainAccountID )
1047
1047
defer unlockAccount ()
1048
1048
1049
- newUser := types .NewRegularUser (userAuth .UserId )
1050
- newUser .AccountID = domainAccountID
1051
- err := am .Store .SaveUser (ctx , store .LockingStrengthUpdate , newUser )
1049
+ user , err := am .Store .GetUserByUserID (ctx , store .LockingStrengthShare , userAuth .UserId )
1052
1050
if err != nil {
1053
- return "" , err
1054
- }
1051
+ if sErr , ok := status .FromError (err ); ok && sErr .Type () == status .NotFound {
1052
+ newUser := types .NewRegularUser (userAuth .UserId )
1053
+ newUser .AccountID = domainAccountID
1054
+ err = am .Store .SaveUser (ctx , store .LockingStrengthUpdate , newUser )
1055
+ if err != nil {
1056
+ return "" , err
1057
+ }
1058
+
1059
+ err = am .addAccountIDToIDPAppMeta (ctx , userAuth .UserId , domainAccountID )
1060
+ if err != nil {
1061
+ return "" , err
1062
+ }
1063
+
1064
+ am .StoreEvent (ctx , userAuth .UserId , userAuth .UserId , domainAccountID , activity .UserJoined , nil )
1065
+ return domainAccountID , nil
1066
+ }
1055
1067
1056
- err = am .addAccountIDToIDPAppMeta (ctx , userAuth .UserId , domainAccountID )
1057
- if err != nil {
1058
1068
return "" , err
1059
1069
}
1060
1070
1061
- am .StoreEvent (ctx , userAuth .UserId , userAuth .UserId , domainAccountID , activity .UserJoined , nil )
1062
-
1063
- return domainAccountID , nil
1071
+ return user .AccountID , nil
1064
1072
}
1065
1073
1066
1074
// redeemInvite checks whether user has been invited and redeems the invite
0 commit comments