Hi, I am having issues with a custom profile page and would appreciate some help.
For the first task I’d like to import the user ID and email to numerous data sets. I was wondering if this could be done via the .onReady in a members page? If so could anyone supply the code to import this?
I’ve tried using the wix guide via the dynamic pages, this guide involves importing the data via a onClick of a login button and I could not get the dynamic page to load up when clicking the my profile. For the level I am at, I’d like to try and stay clear of dynamic pages.
Thanks in advance
Hey
So you mean you have a external file with users in that you want to import as Wix Users? If that is correct you must manually import them using the Contacts & CRM page under the dashboard.
Of you can use the CRM API to create the contacts but the users ID is a WIX created GUID and if you need your own you will have to create a Data Colleciton named maybe UserAttributes and inside that create a reference to WixUsers ID field using a text field and then your own ID.
It needs some code and not super easy, just saying.
I probably used incorrect terminology in my initial post, all my collections are in wix.
As far as I understand it, for a member to edit an existing form you need to pull their ID in to the collection
From the guide I was using:
import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;
then there was an onclick event
export function loginButton_click(event) {
// user is logged in
if(wixUsers.currentUser.loggedIn) {
// log the user out
wixUsers.logout()
.then( () => {
// update buttons accordingly
$w(“#loginButton”).label = “Login”;
$w(“#profileButton”).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(“Members”)
.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(“Members”, toInsert)
.catch( (err) => {
console.log(err);
} );
}
// update buttons accordingly
$w(“#loginButton”).label = “Logout”;
$w(“#profileButton”).show();
} )
.catch( (err) => {
console.log(err);
} );
}
}
Now as I understand it, this onclick event puts the user ID and email in to the “members” collection.
I was wondering if this kind of code could be changed to an onReady event and put the user ID and email in to all of my collections. I have around 12 of them to complete numerous forms.
You can see them here but non work. Excuse the website, it is a mess at the min as I have been trying all sorts to try and get it to work.
https://www.prosopographies.com/account/editorhomepage
Thanks for any help