@@ -1523,13 +1523,23 @@ private void confirmEmail(
15231523 boolean hasHashedEmail = hashedEmail != null && !hashedEmail .isEmpty ();
15241524
15251525 if ((hasEmail || hasHashedEmail ) && user != null ) {
1526+ MParticle .IdentityType selectedIdentityType = null ;
1527+ try {
1528+ String identityTypeStr = (kitConfiguration != null )
1529+ ? kitConfiguration .getHashedEmailUserIdentityType ()
1530+ : null ;
1531+ if (identityTypeStr != null && !identityTypeStr .equalsIgnoreCase ("Unknown" )) {
1532+ selectedIdentityType = MParticle .IdentityType .valueOf (identityTypeStr );
1533+ }
1534+ } catch (IllegalArgumentException e ) {
1535+ selectedIdentityType = MParticle .IdentityType .Other ; // fallback if invalid value
1536+ }
15261537 String existingEmail = user .getUserIdentities ().get (MParticle .IdentityType .Email );
1527- String existingHashedEmail = user .getUserIdentities ().get (MParticle .IdentityType .Other );
1528-
1538+ String existingHashedEmail = selectedIdentityType != null ? user .getUserIdentities ().get (selectedIdentityType ) : null ;
15291539 boolean emailMismatch = hasEmail && !email .equalsIgnoreCase (existingEmail );
15301540 boolean hashedEmailMismatch = hasHashedEmail && !hashedEmail .equalsIgnoreCase (existingHashedEmail );
15311541
1532- if (emailMismatch || hashedEmailMismatch ) {
1542+ if (emailMismatch || ( hashedEmailMismatch && selectedIdentityType != null ) ) {
15331543 // If there's an existing email but it doesn't match the passed-in email, log a warning
15341544 if (emailMismatch && existingEmail != null ) {
15351545 Logger .warning (String .format (
@@ -1553,20 +1563,8 @@ else if (hashedEmailMismatch && existingHashedEmail != null) {
15531563 if (emailMismatch ) {
15541564 identityBuilder .email (email );
15551565 }
1556- if (hashedEmailMismatch && kitConfiguration != null ) {
1557- MParticle .IdentityType type = null ;
1558- try {
1559- String identityTypeStr = kitConfiguration .getHashedEmailUserIdentityType ();
1560- if (identityTypeStr != null && !identityTypeStr .equalsIgnoreCase ("UNASSIGNED" )) {
1561- type = MParticle .IdentityType .valueOf (identityTypeStr );
1562- }
1563- } catch (IllegalArgumentException e ) {
1564- type = MParticle .IdentityType .Other ; // fallback if invalid
1565- }
1566-
1567- if (type != null ) {
1568- identityBuilder .userIdentity (type , hashedEmail );
1569- }
1566+ if (hashedEmailMismatch && selectedIdentityType != null ) {
1567+ identityBuilder .userIdentity (selectedIdentityType , hashedEmail );
15701568 }
15711569
15721570 IdentityApiRequest identityRequest = identityBuilder .build ();
0 commit comments