Wix DataInsert not inserting(Solved)


I created a button and set it to insert the current user Idand Email to my collection.
I also Inserted the get current user using wix-users.
I can see the user Id but the email field is blank.
Any Ideas why?

Hello! First gues, might be wrong. I don’t see code where you getting those id and email of current user

Based on code you pasted, you’re just filling in empty values
You first define variable (let userId), then gather object from it - but it’s empty


You should change “let userID; let userEmail” to smth like this:

let user = wixUsers.currentUser;
let userId = user.id;           
  .then( (email) => {
    let userEmail = email;      
  } );

and, add

 import wixUsers from 'wix-users';  

in order to use this module

Hi, thanks for your replay,
I have the 'wix-users’at the begging of the code with Onready() so Im getting the current user as the page loads. And thats also the reason the user Id is being inserted. but the problem is with the user email.
what else can it be?

I see “let userEmail” at the beginning of the function. Doing this makes this variable undefined
Like this - https://www.screencast.com/t/aHimPZlygrk

Can you try to add


right after

let userId;
let userEmail;

My guess it will be undefined
Anyway, i could mistake)

Hi, thanks again for trying to help. I tried what youre saying, but unfortunately its not workinh. It doesn’t say its undefined but it still doesn’t work.

Can you send a link to the site where you try to do this? I can try to troubleshoot it

Hi, thanks for getting back.
You can go to this link , I’ve created a page for you to test the button.
just letting you know that when I click the button thats what I get in the collection:

Hi, just checking here again… Is there any other idea on how to insert usrers email?

Hi Faidda,

I took a look at your test page code.
Your code assumes that theres a user logged in.
You should verify it by using ‘loggedIn’ flag.

const user = wixUsers.currentUser;
if (user.loggedIn) {
    user.getEmail().then(email => {
        //do insert here.

Let me know how it goes :slight_smile:


1 Like

Thank you so much! it did work :slight_smile: