Code and Wix question combined...what happens with user input data if their email changes? Owner recognition issues?

  1. If they change emails and forget password…how do they get a new password?

  2. And if new email/password assigned, then what happens to user generated information as it based on owner ID database fields?

  1. they click forgot password, they will then receive an email from wix, with a big wix logo on the top of the email which will allow them to create a new password.

  2. the owner ID stays the same if they change their email/password.

LOL…bear with me. tearing apart to make sure on building for the future. Many, myself included) have tabbed items by pulling in email for databases. However, by using such user email it then could create issues down the road. So if the user/owner ID remains same no matter email change or not, need to pull in Owner ID rather than email.

As always, glad to see your responses Mike…

So need to find/replace code for pulling in user email and get Owner ID

Can I do some replacing of items to shift this from email insert to Owner ID? Seems obvious, but as a newbie I miss the obvious oops a lot

import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;

$w.onReady( () => {
if (wixUsers.currentUser.loggedIn) {
$w(“#button7”).label = “Logout”;
$w(“#button9”).show();
}
else {
$w(“#button7”).label = “Login”;
$w(“#button9”).hide();
}
} );

export function button7_onclick() {
// user is logged in
if (wixUsers.currentUser.loggedIn) {
// log the user out
wixUsers.logout()
.then( () => {
// update buttons accordingly
$w(“#button7”).label = “Login”;
$w(“#button9”).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(“Profile”)
.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(“Profile”, toInsert)
. catch ( (err) => {
console.log(err);
} );
}
// update buttons accordingly
$w(“#button7”).label = “Logout”;
$w(“#button9”).show();
} )
. catch ( (err) => {
console.log(err);
} );
}
}

export function button9_onclick() {
wixLocation.to(/create-member-profile);
}

@jeff-haskins
In that code you have inserted both the email and userId to the “Profile” database. You should not be inserting userId into the " _id " field key of the database though. Best create a new column for that.

@mikemoynihan99 Yes…so to alleviate my worries, and not capture email for future, use userID instead…just eliminate the email line here:

const toInsert = { “_id”: userId,
“email”: userEmail

and change that _id to ID User or something or another

@jeff-haskins
if all you require is a unique identifier for the user in your database then go with the userID

@mikemoynihan99 in looking through items since I have both a personal and business profile set up. The owner id is of course the same, but a new _id is created for the business (it being second profile created). That could be handy for future filtering. If I shift that into a newly created field with my above code, am I altering that function? Will my new field still = the _id field ??

@mikemoynihan99 One other question, and I will then leave you alone…

In database it has set up fields of _owner where is the _id or userID created within the database set up? Is it calling the _owner to set up a duplicate field and why? Or is that what you were referring to by changing the code so it does not place the insert into the _id

thus I have had changes created to the _id by my code inserting a duplicate of the _owner into field when they actually should have been different?

@jeff-haskins
every wix database has a field key called “_id” this is a unique identifier for that row of data and generally should not be changed. If your wanting to pass data to the database you could create a new field key and pass it to that instead.

@mikemoynihan99 So by using the code I did, it actually just duplicated the owner ID into that field, rather than a unique identifier appearing there? Thanks for helping me clarify in my mind!

@mikemoynihan99 Thanks again, Mike. I made that easy change of creating new field that duplicates the owner ID for use. I left the email insert as never know, might be useful at some point. Awesome help on this!!!

Wix does not currently support a member changing their email for log in purposes. But would recommend folks not use emails as user identifier as that may change. Should a person ever change emails, an Admin can allow them to use a new email log in, but then just use that unique field created for owner ID and replace it with the old owner ID (they then have two owner IDs with one being the login created, and the other being the old). This way any material created for the future will still match the old account material inserted into database by user,

And if you are doing work with businesses, it makes for an easy shift of material if account management changes. New manager just gets the old user ID field you created. However, I still have to figure out how the fact that dataset filter or owner = logged in user will not function for this new identity as far as permissions on the database.

So past material will still carry through in eyes of site visitor seeing as same entity, but new user will not be able to edit the past material and will still have to manually shift profile page info. Thoughts on recreating easily??

add a members area to your site, the user will then be able to update their First Name, Last Name, Phone Number, Email, etc.

Also if you want you can manually go into the members section on your site dashboard and manually change their email yourself.

@mikemoynihan99 from what I see, it will not allow them to change their log in email.

@jeff-haskins
I have not tried it personally but it would seem a bit ridiculous of wix if the user updates their email on the wix site and then still has to use another email to log in…

@mikemoynihan99 yep. but that appears to be the case from what I can tell…a member can not change sign in email. I did away with the members area as I am building my own network and it creates a duplication of profile info because I am limited in what I can delete on their profile pages. I just have the login in use currently.

@mikemoynihan99 Here is member page (they can not change login email

@jeff-haskins

@mikemoynihan99 You can change the contact email, but it does not change the login email. No way to change that by member or site owner. If members are a business…this becomes a huge issue as those handling the page can change, as can emails.