[SOLVED] I really need some help, please.

Hi, before I upgrade my site to premium all worked well but after that, I’ve found a quite a big problem.
When someone creates new profile it’s work well and I can see him in Contacts app

but problem is that for some reason members are save to Contacts list but not to member database.


This is my full code:

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

$w.onReady( () => {
  if(wixUsers.currentUser.loggedIn) {
    $w("#loginButton").label = "Odhlásit se";
    $w("#profileButton").show();
  }
  else {
    $w("#loginButton").label = "Přihlásit se";
    $w("#profileButton").hide();
  }
} );

export function loginButton_click(event, $w) { 
  // user is logged in
  if(wixUsers.currentUser.loggedIn) {
    // log the user out
    wixUsers.logout()
      .then( () => {
        // update buttons accordingly
        $w("#loginButton").label = "login";
        $w("#profileButton").hide();
    } );
  }
  // user is logged out
  else {
    let userId;
    let userEmail;
    
     // 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
          };
          // add the item to the collection
          wixData.insert("Members", toInsert)
            .catch( (err) => {
              console.log(err);
            } );
        }
        // update buttons accordingly
        $w("#loginButton").label = "Odhlásit se";
        $w("#profileButton").show();
      } )
      .catch( (err) => {
        console.log(err);
      } );
  }
}
export function profileButton_click(event) {
  wixLocation.to(`/Members/${wixUsers.currentUser.id}`); 
}

Thanks for any advice,
Jakub

Hi Jakub

From experience, this could be one of two things. First, check that your database is spelled exactly the same as in your page code, capital letters included. If this checks out, set all your database permissions to ‘anyone’ and give it a try. This usually does the trick.

Best of luck!
Tiaan

Hi Tiaan,
thanks for tips but I tried them all, even now, one more time for to be sure.
I really don’t understand where is the problem. It worked before my premium plan but now it’s not. The same code with same specs is working on my test site but not where I really need it to. Anyway, I’ll not give up.

Thanks,
Jakub

Hi Jakub

That is strange. Another thing that I can think of is to double check the link connections between the login’s button onClick event and the code. I have seen before that if I move a button out of the header and then back in, it breaks the connection. Also check that your login button is not linked to any other pages with the UI

Let me know,
Tiaan

Hi Tiaan,
Thanks for another tip, buts it’s still not working. I also tried sync data between Sandbox and Live Collections but without success.

Jakub

nobody knows whats wrong?

Hi Jakub,
Tiaan pointed out the most common issue.
But first of all, just to make things clear:
There is no automatic connection between you contacts and members collection.
Please see here a long and useful discussion about what happens and how to deal with that.

Liran.

Hi Jakub,

We located an issue on your site and working on a fix.
We will provide feedback as soon as we have any.

Hi,

I tried signing up to your site and I can see new line was added to your live Member collection.
Can you try again and let us know if it works ?

hmm… all works perfectly!!! Thank you so much! =)

You really made my day … thanks again. =)

Hi,

Is there a way, how to import user data into the member’s database, while using the custom registration?
With the current code that I have, all new members are visible in the Contact List and Site Members, but not in my member’s database.

I’m trying to solve the problem here:

https://www.wix.com/corvid/forum/community-discussion/custom-registration-1/p-1/dl-5da9bb66078675001742691c-5da8e3a3110dd1002d688e43-2

Let me also share my code, and if any of you will be able to help, I would very much appreciate it.

  1. The registration code:
import wixUsers from 'wix-users';
import wixLocation from 'wix-location';
import wixWindow from 'wix-window';

$w.onReady(function(){  
    $w('#register').onClick(function (){   
 
 let email = $w('#email').value; 
 let password = $w('#password').value;   

        wixUsers.register(email,password)   
        .then(()=>{
        wixWindow.lightbox.close();
        wixWindow.openLightbox("Přihlášení");
            })
        })
    })
  1. The login code:
import wixUsers from 'wix-users';
import wixLocation from 'wix-location';
import wixWindow from 'wix-window';

$w.onReady(function () {
$w("#forgotPassword").onClick( (event) => {
wixWindow.lightbox.close()
   wixUsers.promptForgotPassword()
   .then( ( ) => {
 
   } )
    .catch( (err) => {
 let errorMsg = err;  //"The user closed the forgot password dialog"
    });
 });
});

export function loginButton_click(event) {

 let email = $w("#email").value;
 let password = $w("#password").value;

 wixUsers.login(email, password)
   .then( () => {
     console.log("User is logged in");
     wixLocation.to(`/Members/${wixUsers.currentUser.id}`); 
   } )
    .catch( (err) => {
     console.log(err);
     $w("#errorMessage").show();  
 // You can delete this line if you are not going to add an error message.  Use a regular text element set to 'collapse on load' from the Properties Panel.
   } ); 
}


Thank you,
Jakub