Hi
I have a custom login and I want to include forgotten password. I used code below.
When I click on forgotten password, it just opens a blank page. Please can someone assist with this.
import wixUsers from ‘wix-users’;
import wixLocation from ‘wix-location’;
$w.onReady( function (){
$w('#enterSite').onClick( **function** (){
let email = $w(“#email”);
let password = $w(“#password”);
wixUsers.login(email, password)
.then( () => {
console.log(“User is logged in”);
} )
. catch ( (err) => {
console.log(err);
} );
} );
} );
export function enterSite_click(event) {
wixLocation.to(/my-page/${wixUsers.currentUser.id}
);
}
// …
$w.onReady( function (){
$w(‘#passwordReset’).onClick( function (){
wixUsers.promptForgotPassword()
.then( ( ) => {
console.log(“Password reset submitted”);
} )
. catch ( (err) => {
let errorMsg = err; //“The user closed the forgot password dialog”
} );
});
});
Hey
You should only have one $w.onReady( function (){ on your page I believe and the click events should all be outside of those events.
Hi Andreas
Thank you for responding. I am a newbie at coding and still finding my way so any help is appreciated.
I changed the code to below and still no joy.
import wixUsers from ‘wix-users’;
import wixLocation from ‘wix-location’;
$w.onReady( function (){
$w('#enterSite').onClick( **function** (){
let email = $w(“#email”);
let password = $w(“#password”);
wixUsers.login(email, password)
.then( () => {
console.log(“User is logged in”);
} )
. catch ( (err) => {
console.log(err);
} );
} );
} );
export function enterSite_click(event) {
wixLocation.to(/home/${wixUsers.currentUser.id}
);
}
export function passwordReset_click(event) {
wixUsers.promptForgotPassword()
.then( ( ) => {
console.log(“Password reset submitted”);
} )
. catch ( (err) => {
let errorMsg = err; //“The user closed the forgot password dialog”
});
}
@paven6996 Please add a screenshot of the page please so I can see the elements you have
@paven6996 Try the below, you had two click events for the same element, not a good idea.
import wixUsers from 'wix-users';
import wixLocation from 'wix-location';
$w.onReady(function(){
});
export function enterSite_click(event) {
let email = $w("#email");
let password = $w("#password");
wixUsers.login(email, password)
.then( () => {
console.log("User is logged in");
wixLocation.to(`/home/${wixUsers.currentUser.id}`);
} )
.catch( (err) => {
console.log(err);
} );
}
export function passwordReset_click(event) {
wixUsers.promptForgotPassword()
.then( ( ) => {
console.log("Password reset submitted");
} )
.catch( (err) => {
let errorMsg = err; //"The user closed the forgot password dialog"
});
}
@andreas-kviby
Hi, I was able to get it working using below code. I need more help though. On the custom registration page, if you enter an email that is already registered, it does not do anything. How do I display an error if an email already exists?
Also, on the custom login page, if an incorrect email or password is entered, it also does not do anything. Would also like to be able to display an error message here.
Lastly is there a way to set a min and max value in the custom phone field?
import wixUsers from ‘wix-users’;
import wixLocation from ‘wix-location’;
$w.onReady( function (){
$w('#loginNow').onClick( **function** (){
let email = $w(‘#loginEmail’).value;
let password = $w(‘#loginPassword’).value;
wixUsers.login(email,password)
.then(()=>{
wixLocation.to('/my-page');
})
})
})
export function passwordRecovery_click(event) {
wixUsers.promptForgotPassword()
.then( ( ) => {
console.log(“Password reset submitted”);
} )
. catch ( (err) => {
let errorMsg = err; //“The user closed the forgot password dialog”
});
}