Hi there,
This is my first time posting on this forum, and I have tried very hard to avoid it, because I do believe it is best to spend the time to go through the references and learn it yourself if possible. But on this issue, I’ve gotten kind of stumped. I’m relatively new to code, and am currently learning Javascript to help me better understand some of the things going on in Wix Code. I do feel I’ve got a pretty good handle on it now, but I’m stuck right here.
Okay here’s what I’m trying to do. I’ve set up a custom database for when people purchase a paid plan on my site, and I’ve set the code to assign them a Member Role after purchasing, which gives them access to a specific page on the site where they can use an online tool I’ve created. So far, that part of the code works fine. But I also want to insert the Member’s Login Email as a field in my custom database, so I can filter their purchases on another page. I can’t for the life of me figure out how to get their email and include it in the “onPlanPurchased” event which inserts the data.
(side note: I can’t use “Owner is Logged-In User” because the owner for every entry is always me, even when it’s someone else logged in. I assume this is because the data entry is not from the user, but from my code on the backend. So instead I’m thinking I’ll filter by email, matched to the “private-member-data” collection.)
Below I’ve pasted what my code currently looks like, please let me know what I need to do to get the email of the current user , and include it in this database entry when they purchase a plan. For this example, the database I’m adding data to here is called “PaidPlans-ManualDataRetrieval”.
Any help or insight is greatly appreciated!
-Jared
import wixData from ‘wix-data’ ;
import { authorization } from ‘wix-members-backend’ ;
export function wixPaidPlans_onPlanPurchased ( event ) {
**let** orderData = {
"title" : event . order . planName ,
"data" : event . order ,
"memberId" : event . order . memberId ,
};
wixData . insert ( "PaidPlans-ManualDataRetrieval" , orderData );
const roleId = “6c3b83ea-04e8-4470-9e06-8861b6d8c2dd” ;
const memberId = event . order . memberId ;
const options = {
suppressAuth : false
};
return authorization . assignRole ( roleId , memberId , options )
. then (() => {
console . log ( “Role assigned to member” );
})
. catch (( error ) => {
console . error ( error );
});
}