@@ -3,7 +3,7 @@ const { HttpStatusError } = require('@microfleet/validation');
33const challengeAct = require ( './challenges/challenge' ) ;
44const redisKey = require ( './key' ) ;
55const handlePipeline = require ( './pipeline-error' ) ;
6- const { getInternalData , getUserId } = require ( './userData' ) ;
6+ const { getUserId } = require ( './userData' ) ;
77const {
88 USERS_CONTACTS ,
99 USERS_DEFAULT_CONTACT ,
@@ -64,11 +64,8 @@ async function removeAllEmailContactsOfUser(redisPipe, userId, exceptEmail) {
6464 }
6565}
6666
67- async function replaceUserName ( redisPipe , userId , verifiedEmail ) {
67+ async function setUserName ( redisPipe , userId , verifiedEmail ) {
6868 const { config : { jwt : { defaultAudience } } } = this ;
69- const internalData = await getInternalData . call ( this , userId ) ;
70- const username = internalData [ USERS_USERNAME_FIELD ] ;
71- redisPipe . hdel ( USERS_USERNAME_TO_ID , username ) ;
7269 redisPipe . hset ( USERS_USERNAME_TO_ID , verifiedEmail , userId ) ;
7370 redisPipe . hset ( redisKey ( userId , USERS_DATA ) , USERS_USERNAME_FIELD , verifiedEmail ) ;
7471 redisPipe . hset ( redisKey ( userId , USERS_METADATA , defaultAudience ) , USERS_USERNAME_FIELD , JSON . stringify ( verifiedEmail ) ) ;
@@ -176,7 +173,7 @@ async function verifyEmail({ secret }) {
176173 await removeAllEmailContactsOfUser . call ( this , pipe , userId , contact . value ) ;
177174 }
178175 if ( this . config . contacts . updateUsername ) {
179- await replaceUserName . call ( this , pipe , userId , contact . value ) ;
176+ await setUserName . call ( this , pipe , userId , contact . value ) ;
180177 }
181178 pipe . hset ( key , 'verified' , 'true' ) ;
182179 metadata . contact . verified = true ;
@@ -241,6 +238,10 @@ async function remove({ userId, contact }) {
241238 pipe . del ( key ) ;
242239 pipe . srem ( redisKey ( userId , USERS_CONTACTS ) , contact . value ) ;
243240
241+ if ( this . config . contacts . updateUsername ) {
242+ pipe . hdel ( USERS_USERNAME_TO_ID , contact . value ) ;
243+ }
244+
244245 return pipe . exec ( ) . then ( handlePipeline ) ;
245246}
246247
0 commit comments