Hello,
would you please help me with following problem: I have a page with Login button and I would like when user logs in - a code to be executed which checks if customer exist and if yes - to redirect it to a specific page , if customer is new - redirect him to another page.
Here is the code but it never gets executed - I am not redirected to neither page …:
import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;
wixUsers.onLogin( (user) => {
user = wixUsers.currentUser;
user.getEmail()
.then( (email) => {
let userEmail = email; // “user@something.com”
wixData.query(“mydatabasewithusers”)
.eq(“contacts_userEmail”, userEmail)
.find()
.then( (results) => {
if(results.items.length <= 0 ) {
//redirect to New User creation
wixLocation.to(‘/NewUser’);
} else {
//redirect to existing user info Dashboard
wixLocation.to(‘/ExistingUsers/Dashboard’);
}
});
} );
});