Cannot assign two different roles using dropdown in registration form

Hi, I would like to assign 2 roles while filling in the registration form by using dropdown in form. But i receive this error message in my “switch case” statement:
cannot redeclare block-scoped variable ‘email’.
How can I solve this issue please?
Here below my code:

import wixUsers from ‘wix-users’ ;

import { assignRole } from ‘backend/role’ ;

$w . onReady ( function (){
$w ( ‘#register’ ). onClick ( function (){

    $w ( "#dropdown1" ). onChange (( event ) => { 
        **let**  valeur  =  $w ( "#dropdown1" ). value ; 
        **switch**  ( valeur ){ 
            **case**  'candidat' : 
                **let**  email  =  $w ( "#email" ).  value ; 
                **let**  password  =  $w ( "#password" ).  value ; 
                **let**  first  =  $w ( "#fname" ).  value ; 
                **let**  last  =  $w ( "#lastName" ).  value ; 
                

                wixUsers . register ( email ,  password , { 
                    contactInfo : { 
                "firstName" :  first , 
                "lastName" :  last 
                } 
                }) 
                
                . then (( results ) => { 
                **let**  roleId = "c3cdf74a-3b34-457b-8d1f-c4199a852d60" ; 
                    assignRole ( roleId ,  results .  user .  id ); 
                } 
                ); 
                **break** ; 
            **case**  'recruteur' : 
                **let**  email  =  $w ( "#email" ).  value ; 
                **let**  password  =  $w ( "#password" ).  value ; 
                **let**  first  =  $w ( "#fname" ).  value ; 
                **let**  last  =  $w ( "#lastName" ).  value ; 
                

                wixUsers . register ( email ,  password , { 
                    contactInfo : { 
                "firstName" :  first , 
                "lastName" :  last 
                } 
                }) 
                
                . then (( results ) => { 
                **let**  roleId = "88770d13-8309-4837-94f8-fd20d60f81bb" ; 
                    assignRole ( roleId ,  results .  user .  id ); 
                    **debugger** ; 
                } 
                ); 
                **break** ; 

        } 

    }); 
    
});  

})

1 Like

Hi, I think you should just declare the 4 variables: email, password, first and last before this line: $w(“#dropdown1”).onChange((event)

and then, when you need them you make only the assignments (without writing let).

Thanks! I made the changes and it works!