User ID from collections not connecting to Wix Site Members

Hello all,
Pretty new to Wix Code and I’m doing pretty well aside from this one issue.

I’ve set up a lengthy user input form that one is required to fill out before signing up. They submit the form to my collection which automatically creates a dynamic user page from linked by user ID. Once they hit that submit button from the user input form it takes them to a page to “finalize” their membership by signing up through the Wix members app so they can view their members-only dynamic page.

Issue: I followed the common membership profile code tutorial by Wix Code and made the log-in/logout and view profile buttons. When I click “view profile” it redirects me to a dynamic page that can’t be viewed (403 Error - You don’t have permission) and the URL does not match the ID that was generated in the original user input form and what is in my collection for that email-address. It doesn’t link the user to their proper profile page.

I guess I’m having an issue verifying that Wix Code is actually checking if there is an item with my email address in the “client” collection. But the larger issue is how can I make it connects to the proper ID associated with that email address in my collection? Using code, can I make sure that “my profile” button is linked with that ID code/collection and not the Wix site members made from the Wix signup? I only have them use the old school Wix Signup because they’re members-only pages. Thank you!

Yiou should do it the other way around, first they sign up and gets redirected to your form page after they are logged in so you get the correct user id. Then you have to set the permissions to their dynamic pages to Members Site Users.

I don’t mean to be stubborn but is there absolutely no way to do it the ‘original’ way? I just hate how that sign-up page looks and it screws with my concept. Thanks for any help!

Hello Andreas, I have created a signup page like what you had mentioned. I first ask new members to signup, then after they signup they are directed to a registration page to finish the signup process.

I have noticed that when using safari or other browsers, “sometimes” the page does not send the users to the registration page after signing up and “sometimes” it does. In safari, a prompt shows up (via the safari browser) that says “would you like to remember this password” and when that prompt shows up, it’s almost as if the code is disrupted and does not finish sending the new users to the next registration page - leaving them stranded on the current page and preventing them from completing the registration process.

Any thoughts on how to fix this? Here is the code:

export function signupButton_click(event, $w) {
let userId;
let userEmail;

 // 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("Members") 
      .eq("_id", userId) 
      .find(); 
  } ) 
  .then( (results) => { 
    // if an item for the user is not found 
    if (results.items.length === 0) { 
      // create an item 
      const toInsert = { 
        "_id": userId, 
        "email": userEmail 
      }; 
      // add the item to the collection 
      wixData.insert("Members", toInsert) 
        .catch( (err) => { 
          console.log(err); 
        } ); 
    } 
    // update buttons accordingly and redirect to members Signup page 
    $w("#loginButton").label = "Logout"; 
    $w("#loggedoutMenu").hide(); 
	$w("#loggedinMenu").show(); 
	wixLocation.to(`/Members/Signup/${wixUsers.currentUser.id}`);  
	
  } ) 
  .catch( (err) => { 
    console.log(err); 
  } ); 

}

Hi Eric,

Try clicking the page url in your live Members collection.
You should be redirected to the member page.

If you get an error please paste your editor url here.

Hi Ido,

Thank you for your reply. I am trying to get my users to add more information to their members profile (organically). Meaning, I do not expect them to go in by themselves and submit this information at a later time and the information is needed for the rest of the site to function. So in order to capture this info, I am trying to make for a clean registration process that captures all of that information during that time.

So when clicking “Signup” the site directs users to the signup page. However, sometimes after users login (or create their initial account - via wix login), the code does not direct them to that original signup page. Instead, it leaves them on the main page. To complicate the issue, I have written code to reflect two types of menus: (1) for users that are signed in and (2) the other for members who are not signed in. So when a user signs up (though wix’s signup area), the non-logged in menu hides (and the button for signup) and the logged-in menu shows. Therefore preventing my users from completing the registration. Is there some kind of “hold” code that I need to write for this part of the redirect code:

wixLocation.to (/Members/Signup/${ [wixUsers.currentUser.id](http://wixusers.currentuser.id/) });

The registration is important to complete because based upon the registration criteria, I direct the users to certain Dashboards. So without collecting that info, the users are not directed to the proper dashboards.

I know its alot…

I solved my problem with my original work around (form > signup > dynamic/profile page).

@Rebecca: Do you mind sharing how you solved the problem? I’m trying to do the same (form > signup > dynamic profile page) and having trouble getting it to work.

Hi Florence,
So after I have them submit the form they’re redirected to my “complete signup” page which is the Wix site members page. I modified the code slightly from the above Wix tutorial by removing the line userId = user.id; so it only connects to the Email address and stops adding it twice with two different IDs in my collection.

After signup I have a lightbox that automatically opens that says “my account” with my client database collection connected to. This serves as a private menu. I also set up a button on my main menu called “my account” to trigger this action when the user is logged in. When they logout that button turns into a “log in” button using the same code formula in the Wix Code tutorial. In this lightbox menu I have all of my member’s buttons including “view profile” which is connected with the dynamic pages in my collection.

I hope that’s not a horrible explanation but I haven’t been using Wix Code for long! Good luck.

Please can someone help? I am trying to add a new row to my database collection when a new member clicks a button. Here is the code that i have…

import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;

$w.onReady( function () {
//TODO: write your page related code here…

});

export function Button_click(event, $w) {

let userId;
let userEmail;

userId=wixUsers.id 

  wixData.query("AQAAS") 
 .eq("_id", userId) 
 .find() 
 .then((results)=>{ 

if (results.item.length===0) {
const toInsert = {
“_id”:userId,

     } ; 
     wixData.insert("AQAAS", toInsert) 
     . **catch** ((err)=>{ 
       console.log(err); 
     }); 
   } 

 } 

 )} 

Any suggestions would be much appreciated.
Robin :slight_smile:

Hi,
I’ve just come across your post and it is exactly what I am trying to achieve. My only question is how do you prevent users from clicking ‘sign up’ when logging in through Wix login as surely this would take them to the default signup before requesting additional data?

Many thanks,
Rachel