Hello,
In my I’ve been trying for 2 days now to get the id of the newly registered user but it doesn’t seem to be getting it… It inserts to my collection successfully but with a totally different Id
here’s my code:
function valuesValid () {
return $w('#firstName').valid &&// text input
$w('#lastName').valid &&// text input
$w('#artistName').valid &&// text input
$w('#dropdown1').valid &&// dropdown
$w('#input25').valid &&// text input
$w('#email').valid &&// text input
$w('#password').valid;// text input
}
function errorMessage () {
$w('#errorMessage').show()// text
$w('#button68').enable()// Button
$w('#button68').label = 'Sign up'
setTimeout(()=>{
$w('#errorMessage').hide('fade')
}, 10000)
}
export function button68_click(event) { // Sign up button
// This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
// Add your code for this event here:
$w('#button68').disable()
$w('#button68').label = 'Signing you up...'
if (valuesValid()) {// If the input and dropdown values are valid
let email = $w('#email').value
let password = $w('#password').value
// prompt the user to log in
wixUsers.register(email, password, {
contactInfo: {
"firstName": $w('#firstName').value,
"lastName": $w('#lastName').value + " [" + $w('#artistName').value + "]",
}
} )
.then( (user) => { //
let resultStatus = user.status;
let userId = user.id; // "r5gduicme-6fem-485j-djre-4843h4kjc349"
const toInsert = {
"_id": userId,
"email": $w('#email').value,
"firstName": $w('#firstName').value,
"lastName": $w('#lastName').value,
"artistName" : $w('#artistName').value,
"gender" : $w('#dropdown1').value,
"pimage" : 'https://bon26.netlify.app/no%20profile%20picture%20soundlytude.png',
"pwallpaper": "https://i.pinimg.com/originals/19/ea/92/19ea92a25b3867c2f0286df57cd0e0da.jpg",
"miniBiography" : "Hey there! I'm using Soundlytude to share my music",
"followerCount" : 0,
"followingCount" : 0,
"totalUploads" : 0,
};
// add the item to the collection
wixData.insert("Members", toInsert)
.catch( (err) => {// catch the inserting to collection error
console.log(err);
$w('#errorMessage').text = "Somehing isn't right, Failed to Insert Data...Please try again. Error: " + err
errorMessage()
} )
} )
.catch( (err) => {// If the sign up didn't work due to network connection, excessive cache etc..
console.log(err);
$w('#errorMessage').text = "Somehing isn't right, Couldn't sign you up...Please try again. Error: " + err
errorMessage()
} );
} else{// If the input and dropdown values invalid (aren't valid)
$w('#errorMessage').text = "Somehing isn't right, There's an Invalid or Missing Property"
errorMessage()
}
}
All my code is working correctly except the id is inserting the wrong one which can make me link to their profile (custom member profile) example /members/${wixUsers.currentUser.id}
cuz the dynamic page id won’t be the current users id which will then result to a ‘not found’ 404 page
any help would be greatly appreciated…
DJ bon26