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
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}`);
}
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.
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.
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
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.
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.
Let me also share my code, and if any of you will be able to help, I would very much appreciate it.
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í");
})
})
})
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.
} );
}