Use Before/After-insert on PrivateMembersData Collection

Hi all, i am trying to get the info from the PrivateMembersData Collection, i’ d like to use the beforeInsert() method or the afterInsert() method to get the data form the member that is going to “sign in”, in order to store them in another database since PrivateMembersData does not support any aggiuntive field. It seems like i cannot use this method (generated by the “hooks” button) on this specific database (PrivateMembersData). Any suggestion?

Did you manage to find a solution to your probleme? Is it possible to have hooks on the PrivateMembreData collection?

Actually i did not, i am trying to manage it using a new database and triggering it when the User clicks the button that is important in my site. Maybe you can try a similar solution

@bodiroga11 thx you. So if I understand correctly you have a second collection where you store all the custom data and link that with the user._id to the main privateMemberData collection ?

If that’s your solution It won’t work in my case. I want to be aware if the user change it’s first name or last name or phone number which are field from the privateMembersData collection.

@plomteuxquentin i think that privateMemberData is almost untouchable, you can only query it. The only thing that comes to my mind would be adding a trigger when the user uses the “change firstName/lastName/Number” and maybe store on a new database the information you need.

I needed to check if a user already clicked that button, so i stored in a db all the users that clicked it.
Another solution could be create a custom log-in with a database that you can modify.

Remember to set the authorization for all the users and not only for the admin on the database settings page.

@bodiroga11 Ok I thought about it last night and I think that the best solution for me would be to query both collections every time I need info about a member. Not the most efficient but that’s the simplest.

Thx for you help! :slight_smile:

I am trying to do something similar: I have a custom registration form, but I need some of the data saved to a custom collection in addition to the PrivateMembersData collection. At the moment I can get the data saved in both places, but the owner IDs do not line up… Is there a way to have the members data saved at registration to both collections and have the Owner ID match?

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

$w.onReady( function () {
$w(‘#registerNow’).onClick( () => {
let emails = [];

emails.push($w('#registerEmail').value); 

// register as member using form data
wixUsers.register($w(‘#registerEmail’).value, $w(‘#registerPassword’).value, {
“contactInfo”: {
“firstName”: $w(‘#firstName’).value,
“lastName”: $w(‘#lastName’).value,
“handle”: $w(‘#handle’).value,
“emails”: emails,
}
});
userDataPopulate(‘#firstName’, ‘#lastName’, ‘#handle’);

function userDataPopulate(firstName, lastName, handle){
//Create data in UserProfileData
let user = wixUsers.currentUser;
let userId = user.id;
wixData.insert(‘UserProfileData’, {
_owner: userId,
firstName: $w(‘#firstName’).value,
lastName: $w(‘#lastName’).value,
handle: $w(‘#handle’).value,
});
}
})
});

import wixUsers from 'wix-users';
import wixUsersBackend from 'wix-users-backend';
import wixData from 'wix-data';
import wixLocation from 'wix-location';
import wixWindow from 'wix-window';
let registration;
$w.onReady(function() {
let userId;
let currentUser = wixUsers.currentUser.id
if (wixUsers.currentUser.loggedin) {
//Url for the Logged in user with ID
wixLocation.to(`/login/${wixUsers.currentUser.id}`);

}
$w("#registerButton").onClick((event) => {
console.log("Button was clicked"); //RegisterButton Clicked
$w("#errorMessage").hide(); // error message "Oops! Check your info and try again"
$w("#emailExists").hide();  //error message "The email already exists"


// custom registration form
if ($w("#email").valid && $w("#password").valid && $w("#firstName").valid && $w("#lastName").valid) {
let email = $w("#email").value;
let password = $w("#password").value;
let first = $w("#firstName").value;
let last = $w("#lastName").value;


wixUsers.register(email, password, {  //registering user email, firstName, lastName, password
contactInfo:{
"firstName": first,
"lastName": last,
"_id": wixUsers.currentUser.id,
"verified": "notAuthorized",
}
})
.then ((result) => {
userId = result.user.id;
console.log(userId);
console.log('checking if the ID is valid')
if(userId.length !== 0) {
console.log('We are getting ready to add them to logins');

console.log('Got all the user data we needed.  Now to insert into logins')
const toInsert = {
"_id": userId,
"emailAddress": email,
"firstName": first,
"lastName": last,
"verified": "notAuthorized"
}
// add data to collection
wixData.insert("logins", toInsert)
.then(() => {
console.log('Successfully added to logins collection')
})
.catch((err) => {
console.log('Sorry, something went wrong!');
console.log(err);
});


}
setTimeout(resetAfterSubmit,500);

})
.catch((err) => {
console.log(err);
});
}
})
});

The resetAfterSubmit is a field reset for the customer. I would suggest only using the wixUsers database for the email and password, and then store all the other information in your own collection. First name Last name etc etc.