Quick Question!

Is there a way to wixLocation.to one page if a user logs in sucessfully but wixLocation.to another page for someone who signs up?

Hi Jamey,

If you implemented the Create Member Profile Pages tutorial, you should already have the code to achieve this.

See line 31 in the code section of the tutorial

  //...
  
  // if an item for the user is not found (user just registered)
  if (results.items.length === 0) {
  //...
  //navigate to a page
  }
  else { //means items was found therefore the user just signed up
  //navigate to other page
  }
  
  //...

Okay I have one of the links working, but the /createaccount/ isn’t working on either button. I think I have the code in the right places but it’s not working, so I’m not sure. I triple checked the url and it’s correct. Am I missing anything?

// prompt the user to log in  
wixUsers.promptLogin( {"mode": "login"} ) 
  .then( (user) => { 
    userId = user.id; 
    return user.getEmail(); 
  } ) 
  .then( (email) => { 
    // check if there is an item for the user in the collection 
    userEmail = email; 
    return wixData.query("Profile") 
      .eq("_id", userId) 
      .find(); 
  } ) 
  .then( (results) => { 
  	wixLocation.to(`/MemberProfile/${wixUsers.currentUser.id}`);<<<<<<This works 
  	// if an item for the user is not found 
    if (results.items.length === 0) { 
    wixLocation.to(`/createaccount/`);<<<<<<<<<<<This doesn't 
      // create an item 
      const toInsert = { 
        "_id": userId, 
        "email": userEmail 
      }; 
      // add the item to the collection 
      wixData.insert("Members", toInsert) 
        .catch( (err) => { 
          console.log(err); 
        } ); 

(Second Button)
// prompt the user to log in
wixUsers.promptLogin( {“mode”: “signup”} )
.then( (user) => {
userId = user.id;
return user.getEmail();
} )
.then( (email) => {
// check if there is an item for the user in the collection
userEmail = email;
return wixData.query(“Profile”)
.eq(“_id”, userId)
.find();
} )
.then( (results) => {wixLocation.to(/MemberProfile/${wixUsers.currentUser.id});<<<<<<<This works
// if an item for the user is not found
if (results.items.length === 0) {
wixLocation.to(/createaccount/); <<<<<<<This doesn’t
// create an item
const toInsert = {
“_id”: userId,
“email”: userEmail
};
// add the item to the collection
wixData.insert(“Members”, toInsert)
.catch( (err) => {
console.log(err);
} );
}

Are they in the right location?