i have a problem with with login to Dynamic page.
if the login is successful i want to send the user to the page wixLocation . to ( ‘/members/${wixUsers.currentUser.ID}’ );
And also when the user click btnUpdate i want to send them to wixLocation . to ( ‘/members/update/${wixUsers.currentUser.ID}’ );
guys pls help
import wixUsers from 'wix-users';
import wixData from 'wix-data';
import wixLocation from 'wix-location';
$w.onReady( () => {
if(wixUsers.currentUser.loggedIn){
$w("#btnLogin1").label = "LOGOUT";
$w("#btnProfile").show();
}else{
$w("#btnLogin1").label = "LOGIN";
$w("#btnProfile").hide();
}
});
export function btnLogin1_click(event) {
if(wixUsers.currentUser.loggedIn){
Promise.all( [wixLocation.to('/#page1'), wixUsers.logout()])
.then( ()=> {
$w("#btnLogin1").label = "LOGIN";
$w("#btnProfile").hide();
});
}else{
let userId;
let userEmail;
wixUsers.promptLogin( {"mode": "login"})
.then( (user) => {
userId = user.id;
return user.getEmail();
})
.then( (email) => {
userEmail = email;
return wixData.query("userdata")
.eq("_id",userId)
.find();
})
.then( (results) => {
if(results.items.length ===0){
const toInsert = {
"_id": userId,
"email": userEmail
};
wixData.insert("userdata",toInsert)
.catch( (err) => {
console.log(err);
});
}
$w("#btnLogin1").label = "LOGOUT";
$w("#btnProfile").show();
})
.catch( (err) => {
console.log(err);
});
}
}
export function btnProfile_click(event) {
wixLocation.to('/members/update/${wixUsers.currentUser.ID}');
}