Redirect users on sign-up

Hello, I’ve seen several threads on this and I grabbed this code from one of them. I’m trying to redirect users from the sign-up page to another page where we ask them for more information but it’s not working for me. This is the actual code I’m using. Any advice?

import wixUsers from ‘wix-users’ ;
import wixWindow from ‘wix-window’ ;
import wixLocation from ‘wix-location’ ;

$w . onReady ( function () {

$w ( "#button1" ). onClick ( ( event ) => { 

let email = $w ( “#input3” ). value ;
let password = $w ( “#input4” ). value ;
let first = $w ( “#input1” ). value ;
let last = $w ( “#input2” ). value ;

wixUsers . register ( email , password , {
contactInfo : {
“firstName” : $w ( ‘#input1’ ). value ,
“lastName” : $w ( ‘#input2’ ). value ,
“loginEmail” : $w ( ‘#input3’ ). value ,
}
} )
. then ( ( result ) => {
let resultStatus = result . status ;
wixWindow . lightbox . close ();
wixLocation . to ( “/new-memeber-form” );
} );
} );

});

  1. What exactly does not work ?
  2. Did you modify all element-IDs to fit it to your own project?
  3. Which ERROR do you get ?
  4. Do you use a LIGHTBOX for Sign-Up?

To get some more informations on how to create a custom Log-In, take a look here…
Log-In:
https://russian-dima.wixsite.com/meinewebsite/user-infos
Register:
https://russian-dima.wixsite.com/meinewebsite/blank-9
Redirection:
https://russian-dima.wixsite.com/meinewebsite/website-navigation
Additional-Stuff:
https://russian-dima.wixsite.com/meinewebsite/automatic-registration

Similar post:

How could look like your custom Registration & Login…
https://www.media-junkie.com/login-page
You can test it with the given TEST-ACCOUNTS shown on the TOP of the page.

I’m not getting errors, it just isn’t redirecting. I tried to enter the element IDs and it wouldn’t except them so I used what values were made available to me within the velo editor. (input1, input2, etc.)

The question here is–> What exactly happens AFTER…

wixUsers.register(email, password, {
    contactInfo: {
         "firstName": $w('#input1').value,
         "lastName": $w('#input2').value,
         "loginEmail": $w('#input3').value,
     }
})

Yes —> It follows the —> .then()-code-part…
Where you get some results and trying to redirect…

.then( (result) => {
     let resultStatus = result.status; console.log(results)
     wixWindow.lightbox.close();
     wixLocation.to("/new-memeber-form"); 
}); 

But could it be, that even more happens?
Could it be, that the new registered user immediately and automaticaly will be logged-in after registration?

I have a similar code running on my site…
https://www.media-junkie.com/login-page

You can try to register–> Follow the REGISTER-INSTRUCTIONS & see what happens !

My code has similarity to yours (but a little bit more expanded & complex).

async function start_Registration(){console.log("Registration running...")
 if(uploadAvatarUrl){console.log("Avatar-Setup completed...")
        msg[0] = "";
        msg[1] = "Registration in process...";
        msg[2] = "Please be patient.";
        msg[3] = "";
        msg[4] = "";
        hide_AvatarSetup(), show_infoMessage();
 
        wixUsers.register($w('#'+REFreg[0]).value, $w('#'+REFreg[4]).value,{
            contactInfo: {
 "firstName": $w('#'+REFreg[1]).value,
 "lastName": $w('#'+REFreg[2]).value,
 }
 })
 .then(async(result)=>{console.log("Update-Contact running...")
 let userStatus = await result.status; console.log("User-Status: ", userStatus)
 let userID = await result.user.id; console.log("User-ID: ", userID)
 //--------------------------------
 await updateUserFields(userID, $w('#'+REFreg[1]).value, $w('#'+REFreg[2]).value, uploadAvatarUrl)//, email, avatarURL);
 //--------------------------------
 await updateContactData(userID, uploadAvatarUrl);
            setTimeout(()=>{show_LogIn();},100) 
 })
 .catch((err)=>{let errorMsg = err; console.log(errorMsg);
            msg[0] = "";
            msg[1] = "!!! E-Mail already registered !!!";
            msg[2] = "Please change E-Mail.";
            msg[3] = "";
            msg[4] = "Forgot password ?";
            $w('#boxInfo').style.backgroundColor=colorInvalid, show_infoMessage();
 })
 }
 else {console.log("Avatar-Setup running...")
        $w('#boxInfo').style.backgroundColor=colorInvalid
        msg[0] = "!!! ATTENTION !!!";
        msg[1] = "Avatar-Setup incomplete!";
        msg[2] = "Choose your AVATAR please.";
        msg[3] = "";
        msg[4] = "Possible AVATAR-Formats ---> png/jpg/gif";
        show_AvatarSetup(), show_infoMessage();
 }
}

The only thing you have to understand, is that after registration your redirection won’t work, because you automaticaly are throwing into a log-in-process.

So this one could help you out…
https://www.wix.com/velo/reference/wix-users/onlogin

Place your redirection code there.

Hi Velo-Ninja, our members have to be approved so I wouldn’t think it would take them to a login process. Right now, with the code as is, it just takes them to the sign-up success page as if the redirect doesn’t exist. where in my code do you see that they are throwing into a login process?

I did not see any code-part of —> approving email?

If you want to test if your redirection works or not, just do simply that way…

.then((result)=>{
    let resultStatus = result.status; console.log(resultStatus)
    wixWindow.lightbox.close();
    wixLocation.to("https://www.google.com/"); 
}); 

If you see → the google-page, than it works, if not, something gone wrong :grin:.

Do you mix somehow CODED-RESGISTRATION-PART with NON-CODED-PART?
Can you show the screen what you see after successfull registration?

@russian-dima

The code is exactly as I posted above.

What about…??? Tested?

.then((result)=>{
 let resultStatus = result.status; console.log(resultStatus)
    wixWindow.lightbox.close();
    wixLocation.to("https://www.google.com/"); 
}); 

I assume you will use a part of your REGISTRATION from Wix out of the box.
And a part by code. In most cases, this do not have a HAPPY-END :sweat_smile:.

Either use the wix-out-of-the-box-features, or do everything by custom code.

@russian-dima do you mean test only the .then code within the onReady function?

@jill90840 Test this one…

import wixUsers from 'wix-users';
import wixWindow from 'wix-window';
import wixLocation from 'wix-location';

$w.onReady(function() {
   $w("#button1").onClick(() => {
      let email = $w("#input3").value;
      let password = $w("#input4").value;
      let first = $w("#input1").value;
      let last = $w("#input2").value;

      wixUsers.register(email, password, {
         contactInfo: {
           "firstName": $w('#input1').value,
           "lastName": $w('#input2').value,
           "loginEmail": $w('#input3').value,
         }
     })
     .then((result)=>{
        let resultStatus = result.status; console.log(resultStatus)
        wixWindow.lightbox.close();
        wixLocation.to("https://www.google.com/"); 
     }); 
  });
});

If the redirection do not work, than it surely will interferre with wix-out-of-the-box registration.
And this is also logical.

  1. You use an approvment management wix-feature (not coded!).


And this is exactly the point. After registration, you probably are redirected automatically to the shown page at this pic.

A WORKAROUND for this could be to use a Time-Delay and fire-up a delayed redirection, to your wished page. Change the following code-line…
…from —>

.then((result)=>{
   let resultStatus = result.status; console.log(resultStatus)
   wixWindow.lightbox.close();
   wixLocation.to("https://www.google.com/"); 
}); 

…to —>

.then((result)=>{
   setTimeout(()=>{wixLocation.to("https://www.google.com/");},2500);
   let resultStatus = result.status; console.log(resultStatus)
   wixWindow.lightbox.close(); 
}); 

Try both versions.

@russian-dima I tried both and no go. The test accounts I’m using to test this are showing up as pending members so I don’t think anything is affecting the sign-up. I feel like this should be so much easier than this. I appreciate your help though!

@jill90840
Perhaps you can ask the post-opener of this post for details, how to handle the registration with approving-system.

I am almost sure, that you will have to code your whole registration-form with all its function from scratch. Or at least you will have to deactivate the approving-system which come out ot the wix-box and code this part by your own.

However → Yes, sometimes it is very confusing.

If i am not right, perhaps somebody else have a better idea, a workaround, or even a solution ?

@russian-dima I’m going to open a ticket. It’s ridiculous that it’s this hard to do a simple redirect.

Is your original post code for a Lightbox? You have the following code:

wixWindow.lightbox.close();
wixLocation.to("/new-member-form"); 

What happens in that code is that you first close the Lightbox, and therefore you will never execute the redirect in the next line.

Where are you opening the Lightbox? What you need to do is to perform the redirect when the Lightbox returns, like this:

wixWindow.openLightbox("LightboxName")
.then( (data) => {
    wixLocation.to("/new-member-form"); 
} );

What is the name of the page that you want to redirect to?
This is what you have:
new-memeber-form
Or is it misspelled and it should be
new-member-form

Damn, i also already assumed this, but was not sure. I did not expect, that the lightbox has such an side-effect. Good to know.

@russian-dima Not really a “side-effect”, rather it’s the program logic,

Now, as far as “good to know”, I would suggest Reinheitsgebot.

@yisrael-wix

I would suggest Reinheitsgebot
Haha! :laughing: → “Ich bin dabei!” :wink::beers:

My last test had it right. No luck. What is Reinheitsgebot??

@jill90840 Reinheitsgebot is the Bavarian Beer Purity Law of 1516. Some things are sacred.