Assuming that your user can successfully log in from a button click of your login form, you need the following code:
import wixUsers from ‘wix-users’;
import wixLocation from ‘wix-location’;
import wixWindow from ‘wix-window’;
import wixData from ‘wix-data’;
$w.onReady( function () {
//TODO: write your page related code here…
});
export function button1_click(event, $w) {
//Add your code for this event here:
console.log(“about to login”);
var email = $w(“#email”).value;
var password = $w(“#password”).value;
wixUsers.login(email, password) // login the user
.then( () => { // this .then is important as it’s the PROMISE to go to once the login function has completed
//if(wixUsers.currentUser.loggedIn) { // check to ensure successful login
console.log("User is now logged in");
wixData.query(“Members”) // we now query the new Members collection passing in the email address
.eq(“email”, email)
.find()
.then( (results) => {
let firstItem = results.items[0]; //see item below
console.log("url = " + “/Members/” + firstItem._id);
wixLocation.to(“/Members/” + firstItem._id); //page name
} )
. catch ( (err) => {
let errorMsg = err;
console.log("errorMsg = " + JSON.stringify(errorMsg));
} );
}). catch ( (err) => {
let errorMsg = err;
console.log("errorMsg = " + JSON.stringify(errorMsg));
} );
} // end of button1_click function
I hope this helps! I’ve copied and pasted this but removed some code so hopefully it will work ok for you.
Stuart.