Dynamic Member Database?

I have read through the forums and can’t seem to get a clear how-to on setting up a dynamic member database. I have followed all of the steps here , but I can’t seem to figure out how to connect my wix members with my custom database.

When my members login using the wix app - they are added to my contacts & CRM section with a member tag but they are NOT added to my database. Is there a way to make that happen?

If there isn’t, how do I identify each wix member’s unique ID in order to allow them access to update their own information in my custom database?

2 Likes

Hey Stephanie!
I’m not sure I understand what you want to do with the custom database you created, so I’ll give you a general answer and if it doesn’t suffice, just give me more details on what you’re trying to accomplish :slight_smile:

Each user has a unique id (see https://www.wix.com/code/reference/wix-users.User.html#id ). If you database’s content is generated by the users, you can use the “Owner” field (which is a system field) to filter / find / update records belonging to a specific user (see https://support.wix.com/en/article/how-to-filter-a-page-based-on-the-currently-logged-in-user for an example)

If there’s some other custom behavior you’d like to implement when a user logs in, use a handler on the Login Event ( https://www.wix.com/code/reference/wix-users.html#onLogin ) to create your own custom behavior when a user logs in.

Let me know if that worked for you,
J.

I just posted a similiar question,(https://www.wix.com/code/home/forum/questions-answers/how-to-automatically-add-wix-members-id-s-to-a-database) at least I think it is the same problem. I believe what we are both looking for is this… We both have Dynamic Member Pages setup. But how do we get our new members who sign up, in particular their “Unique Wix Member ID’s” to automatically add/import into the database so we can add content to their profile page specifically for that user.

  • Thanks in advance and any help is appreciated.

  • What I’m trying to do is the following…

  1. New Member signs up on my website (each member has their own Wix Member ID)
  2. Each member that signs up (after my approval) I need to take that Wix Member ID/# and add it into a database (like the literal process of taking the unique Wix Member ID Data and putting it into the database)
  3. This way I can display unique content on each Unique Wix Members ID’s Profile Page.
  • I’m a money management consultant so each user is unique. Im trying to create my website to display different and private data to each Unique Wix Members ID’s but i can’t get new member signups Unique Wix ID’s to automatically add to my database.

Dear :
i use this code
you need to sign out and sign in to let the code check your id
this will check the ID then insert it to the collection if is not in the collection

it’s will check the field number “acnumber” in Members
acnumber = 1000
randf = 1000+1
and it will add title “student1001”


import wixData from 'wix-data';
 import wixLocation from 'wix-location'; 
import wixUsers from 'wix-users';  

$w.onReady( () => {   
user = wixUsers.currentUser;  
userId = user.id; // "r5cme-6fem-485j-djre-4844c49"  
user.getEmail() .then( (email) => {      
userEmail = email; // "user@something.com" 
} );  
   wixData.query("Members") 
.descending("title") 
.find() .then( (results) => { 
         rand = results.items[0]["acnumber"]; 
    randf = `${Number(rand) + 1}`;  
   addrand = ("student"+randf);
 } ); 
});

 export function button1_click() {
 // user is logged in 
if(wixUsers.currentUser.loggedIn) {
           
wixData.query("Members")
 .eq("_id", userId) .find()
 .then((results) => { 
let prrcon = results.items[0]["pr"];  
if (prrcon === "superadmin"){   
       wixLocation.to('/supervisor'); 
} else if(prrcon === "admin") {  
            wixLocation.to('/supervisor'); 
} else if (prrcon === "subadmin" ) {       
      wixLocation.to('/supervisor'); 
} else if (prrcon === "teacher" ) {    
         wixLocation.to('/stu-tsmya'); 
}else { $w('#text44').show(); } }); 
} 
// user is logged out 
else { 
// 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("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,
 "pr": normal,
 "title": addrand,
 "acnumber": randf    
       }; 
// add the item to the collection  
         wixData.insert("Members", toInsert) 
.catch( (err) => {   
            console.log(err); } ); }
 // update buttons accordingly 
$w("#button1").label = "Go to control"; } )
 .catch( (err) => {         console.log(err); } )

; } } 

I hope this will help you

Br

There is a part in a code from the tutorial you linked, that adds new user to the database:

...
...
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);
            } );
            
  ...
  ...
  

if you’ve created the members collection(like it says in the tutorial in Members Collection section), things have to work.
Check if name of collection in a code is same as database/collection you’ve created.

Good luck!

sorry guys I’m a total noob, I was looking within the SandBox… Appreciate the help

Hello.
Sorry , I am not expert but I am improving slowly and getting there! I just need a more detail help on how to make new registered user (I have used a added a members area with login and so on) can be added to my Dynamic Member Pages that I have set up (I am ok with dynamic pages).
Practically my new register users are uploaded in what is called ‘Members/PrivateMembersData’ table but not in the Dynamic Member Page table that I have made.
I need some easy steps to follow as I am quite lost here, despite trying hard. Everything else is done except this issue.

thanks a lot to any kin helper that will assist me.
Regards
andrea

Did you ever figure this out?

maybe i’m too new at this, but i have pasted this code in nearly every place that I can, and I am not seeing how it is generating an ID. If someone has figured this all out, could you please walk me through the process?