Database query and Site User

I’m amending this because I was a little irritated and overwhelmed when I posted the first time.

BLUF: I need to take the user id from my logged in site member and check a database for the ID. If it doesn’t exist I need to create the ID in a “Members” database which is setup minimally with simply an two field keys “title” (user ID) and “privileges.” I’ll be using privileges to add or remove pages from the users account menu based on access level.

Before you ask… yes, I have read the API and “tutorials,” but to be honest I am suffering watching the videos. I prefer to read, but the documentation just isn’t clicking. Watching videos takes an incessant amount of time for directions which might only be a few lines of reading.

There will be more to come, but I can’t go anywhere until I understand how to utlize the Wix databases. I have figured out to get the user id for my site members. I am very familiar with C#, but not javascript, databases, or Wix API. I am really struggling though with figuring out the database information.

Hello Robert,

So, I think that I have an idea for the question. Tell me if I was wrong.

1 – To load current user logged (learn more here )

let user = wixUsers.currentUser;
let userId = user.id;

2 - Get user by id in your user collection and check if it exists. If doesn’t exist add to your collection of users.

wixData.get("users", userId)
.then((results) => {
if (!results) {
//put here the code to save user in collection here
}
})
.catch((err) => {
let errorMsg = err;
});

Good luck :wink: