I have followed this template to create a custom members area but the code for registering new members is very unclear for me because as you can see in the screnshoot of my Members collection only the email adress is added. Other fields like First name, Gender and Age just show "Your name, “Your gender” “Your age” etc. I don´t understand how that info shall be implemented by the members?
Here is the template page:
https://www.wix.com/velo/example/custom-members-area
And the code at their Home page (I have just add some extra personal information):
import { checkIfLoggedIn } from ‘public/repeatFunctions.js’ ;
import { authentication } from ‘wix-members’ ;
import wixData from ‘wix-data’ ;
$w . onReady ( async function () {
$w ( ‘#loginBox’ ). hide ();
$w ( ‘#menu’ ). hide ();
// Check if current member is logged in
let isLoggedIn = await checkIfLoggedIn ();
if ( isLoggedIn === true ) {
// If logged in,
$w ( ‘#menu’ ). show ();
} else {
// If not logged in,
$w ( ‘#loginBox’ ). show ();
$w ( ‘#loginButton’ ). show ();
// When the login button is clicked
$w ( ‘#loginButton’ ). onClick (() => {
authentication
. promptLogin ({ mode : ‘login’ }) // Prompt them to log in
. then (() => {
console . log ( ‘Member is logged in.’ );
$w ( ‘#loginBox’ ). hide ();
$w ( ‘#menu’ ). show ();
})
. catch (( err ) => {
console . log ( ‘There is an issue with the member logging in.’ , err );
});
});
}
});
authentication . onLogin ( async ( member ) => {
const loggedInMember = await member . getMember (); // Get the member’s info when they log in
const currentMemberId = loggedInMember . _id ;
const memberEmail = loggedInMember . loginEmail ;
// Check if the member ID is already stored in the member database collection
return wixData
. query ( ‘Members’ )
. eq ( ‘_id’ , currentMemberId )
. find ()
. then (( results ) => {
// If the member ID is not found,
if ( results . items . length === 0 ) {
// Create default profile items for the new member
const toInsert = {
loginEmail : $w ( ‘#email’ ),
password : $w ( ‘#password’ ),
firstName : $w ( ‘#forename’ ),
age : $w ( ‘#age’ ),
gender : $w ( ‘#gender’ ),
country : $w ( ‘#country’ ),
State : $w ( ‘#state’ ),
language : $w ( ‘#language’ ),
‘https://static.wixstatic.com/media/8b7eef_86dd1719d0cf4694bb523e601a4e5628~mv2.png’ ,
subtitle : ‘Write a short paragraph about yourself.’ ,
favoriteDish : ‘Your Favorite Dish’ ,
};
// Add these items to the member database collection
wixData
. insert ( ‘Members’ , toInsert )
. then (( results ) => {})
. catch (( err ) => {
let errorMsg = err ;
});
}
})
. catch (( error ) => {
console . error ( error );
});
});