Hi! i have a code that add new members info to my database when they login. The problem is that when i test the code on preview mode, it works fine, but when i do it on live mode, nothing happens. Anyone know which should be the problem?
This is my login code ( sorry for the image, an error show up when i try to paste the code).
Thanks!!
The console showed this. The code always gets the same ID, so no new items are created in the database. Help please!
@cryptoirt You’re using login function and at the same time you’re trying to insert the values. That’s why, while login console shows that item already exists.
You can check the collection permissions, sync the database to live and then publish the website.
I hope this helps. If not, then due to connection issues sometimes things not work. So, close the ediyot after saving everything. Re-open editor and check the things again. If everything is fine then it will work.
When looking at your code, i have to say, your way of thinking can’t be right!
Why? → Because the functionality which you want to achieve, can’t work on LOG-IN —> it should work on → REGISTRATION.
When a USER logs-in → he/she already should exist in your DB, because the data was already created during registration-process.
The only scenario i can think of, where you can use the way you do → is for example to show the online-state of all users of your site.
Hi @wix-expert-velo-cert ! where can i sync the database? i have the new version of Wix and i don´t have the sandbox option in my members collection.
@russian-dima you are right, i will try it on registration!
@russian-dima same problem if i do it with registration code! It is like de ID got stuck whatever the user that enters.
Console
Registration Code

@russian-dima if i try with this other code:
The console give me this:
Please heeelp!
In your original code, try to use ‘wixData.save’ instead of ‘wixData.insert’ , maybe will work as you like.
Hi @anas_tick ! I just tried that but it is not working… In the preview mode it is saving the new data of differents users ( always under the same ID) but in the live mode nothing is happening.
The problem is that (don´t know why) Wix is not asigning new ID to new users. Also, i forgot to mention, this code was working fine until i added two wix forms to the members dinamyc page. Could that have anything to do with this?
@anas_tick @russian-dima @wix-expert-velo-cert
I´m trying with the register code and the console gives me:
It is taking always the same ID.
Code:
This is because you’re admin and can’t register in preview mode. Please publish the website and try to register in live mode.
I did it but is the same. I can register and login perfectly , but it always enter to the members page under the same ID.
Can you please paste your code inside a CODE-Block?
I am not really willing to rewrite all the code from a pic.
Then i will check its function.
@russian-dima thank you and sorry for the images! I leave the two codes.
//Registration code
$w.onReady(function(){
$w('#RegButton').onClick(function (){
let firstName = $w("#nombre").value
let lastName = $w("#apellido").value
let email = $w("#email").value
let password = $w("#password").value
let confirmPassword = $w("#confirmPassword").value
if(($w('#password').value===($w('#confirmPassword').value))){
doRegistration(email, password, firstName, lastName)
let user = wixUsers. currentUser;
console. log (user)
let userId = user. id;
console. log (userId)
const toInsert = {
"_id": userId,
"email": email,
"nombre": firstName,
"apellido": lastName,
};
// add the item to the collection
wixData.insert("Members", toInsert)
}
else {
$w("#text40").show()
}
})
})
// Login code
$w.onReady(function(){
$w('#loginNow').onClick(function (){
let email = $w('#email').value;
let password = $w('#password').value;
let userId;
let user = wixUsers. currentUser;
userId = user. id;
wixUsers. login(email,password)
.then( () => {
const milliseconds = 5 * 1000;
setTimeout( function(){
wixLocation. to("/inicio");
} , milliseconds); // this is to put a gif when login runs
$w("#loginNow").hide();
$w("#boxLog").expand();
$w("#text38").hide();
})
.catch( (err) => {
console. log(err);
$w("#text38").show();
})
const toInsert = {
"_id": userId,
"email": email,
"password": password,
};
// add the item to the collection
wixData.insert("Members", toInsert)
})
})
@cryptoirt
Question: Are you trying to generate a custom Login/Registration-page?
Or what is exactly your aim ?
Although i am alsmost sure, that you are trying to generate a custom Login-Registeration-page…, because the wix-standard REGISTRATION do not have a → Password-Corfirmation as i know.
You are using one…
let confirmPassword = $w("#confirmPassword").value
You are not using either the already given PMD(PrivateMembersData), nor you are using the CRM.
So you have generated a separate DATABASE → “Members” where you store all the new generated USER_ACCOUNT_DATA, right?
Now again → what is exactly your issue? Where did you stuck at?
The following part in your REGISTRATION-CODE looks strange…
doRegistration(email, password, firstName, lastName)....
Where is that part —> doRegistration <— of code/function in your code?
Where can be found this function in your code?
Did you show all related code, or are some code-parts missing?
I could also not detect, that you are using any BACK-END-CODING.
Take a look how it should look like…
Register a user as a site member with registration options…
import wixUsers from 'wix-users';
let email = // the user's email addresses
let password = // the user's password
let firstName = // the user's first name
let lastName = // the user's last name
let phone = // the user's phone number
wixUsers.register(email, password, {
contactInfo: {
"firstName": firstName,
"lastName": lastName,
"phones": [phone]
}
})
.then( (result) => {let resultStatus = result.status; console(resultStatus)});
@russian-dima Yes, i did a custom registration-login page. And yes, i want to store all the new generated data in a new database (called Members).
The DoRegistration function is linked to the backend code (created to send emails confirmation when new member register):
//Backend register and mail verification code
import wixUsers from 'wix-users-backend';
import wixData from 'wix-data';
export function doRegistration(email, password, firstName, lastName) {
// register the user
return wixUsers.register(email, password, {
"contactInfo": {
"firstName": firstName,
"lastName": lastName
}
})
.then((results) => {
wixUsers.emailUser('verifyRegistration', results.user .id, {
variables: {
approvalToken: results. approvalToken
}
})
.then((results) => {
return results
});
})
}
export function doApproval(token) {
// approve the user
return wixUsers.approveByToken(token)
// user is now active, but not logged in
// return the session token to log in the user client-side
.then((sessionToken) => {
return { sessionToken, "approved": true };
})
.catch((error) => {
return { "approved": false, "reason": error };
});
}
//Confirmation Mail Code
import wixLocation from 'wix-location';
import wixUsers from 'wix-users';
import {doApproval} from 'backend/register';
$w.onReady( () => {
// get the token from the URL
let token = wixLocation. query.token;
doApproval(token)
} );
$w.onReady(function(){
$w('#buttonYield4').onClick(function (){
wixLocation. to('https:// www.yieldbox .me');
})
})
And i am stuck in the insert ID part. Only the first user who register generate an iD (always the same one).
The others users who register can´t get an ID because the code recognize that they “have” already one (the one that the first user generated).

@cryptoirt
Ok, perhaps now i recognize your issue…
I am not sure if a registered USER is immediately logged in after REGISTRATION-PROCESS (you’ll have to test it [i forgot]), but if so, your idea looks good…
You do the registration → User is already logged-in → you get the users ID and so on…
With a small mistake (i think)…
You do not await till the user is logged-in and you try to get immediately the ID of the current-User.
$w.onReady(function(){
$w('#RegButton').onClick(function (){
let firstName = $w("#nombre").value
let lastName = $w("#apellido").value
let email = $w("#email").value
let password = $w("#password").value
let confirmPassword = $w("#confirmPassword").value
if($w('#password').value === $w('#confirmPassword').value){
doRegistration(email, password, firstName, lastName)
let user = wixUsers.currentUser; console.log (user)
let userId = user.id; console.log (userId)
// and so on......
}
else { /* ... */ }
// and so on......
});
Try this one…
$w.onReady(function(){
$w('#RegButton').onClick(function (){
let firstName = $w("#nombre").value
let lastName = $w("#apellido").value
let email = $w("#email").value
let password = $w("#password").value
let confirmPassword = $w("#confirmPassword").value
if ($w('#password').value === $w('#confirmPassword').value){
doRegistration(email, password, firstName, lastName).then(()=>{
let user = wixUsers.currentUser; console.log(user)
let userId = user.id; console.log("User-ID: ", userId)
// and so on......
});
}
else { /* ... */ }
// and so on......
});
Seems like you are trying to do almost the same functionalities like on my own Login-Project 
https://www.media-junkie.com/login-page
@russian-dima hahah i had forgot that they were your codes! You help me so much with those to do the verification mail!
If you can help me with this ID issue you really are the best. I made your suggested changes and it is showing the same error.
Seems like that ID got stuck and is not allowing new ones to be created.