Hi there!
So I’ve been struggling with this for a few days now. I’m not familiar with backend languages, but I’m starting to get an understanding of it.
I have a database (“Memberinfo”) set up where members can add and update their personal info. I’m trying to write a hook in the backend that automatically adds their login email (_loginEmail from PrivateMembersData) into a column with field key “reference”.
This is what I have so far in data.js :
*I’ve been trying to combine this getEmail code with this bottom example for the save code, within a beforeUpdate hook.
import wixData from 'wix-data';
import wixUsers from 'wix-users';
export function Memberinfo_beforeUpdate(item, context) {
let user = wixUsers.currentUser;
let userId = user.id; // "r5cme-6fem-485j-djre-4844c49"
let isLoggedIn = user.loggedIn; // true
let options = {
"suppressAuth": true,
};
user.getEmail()
.then( (email) => {
let userEmail = email; // "user@something.com"
} );
let toSave = {
"reference": user.getEmail
};
wixData.save("Memberinfo", toSave)
.then( (results) => {
let item = results; //see item below
} )
.catch( (err) => {
let errorMsg = err;
} );
}
The end result is… absolutely nothing. The form updates with no issues, but the reference field remains blank.
What am I missing here?
Thank you so much!
Crystal