Hello, If the user is not logged in, I want to redirect him/her to login page.

Hello, I have a page that every visitor can display and select a date for my service. After the date selection I have a ‘‘go to the payment’’ submit button that redirects users to payment page. However I want to make them members of the website before displaying payment page therefore payment page is members only page. After clicking ‘‘go to the payment’’ button, how can I redirect them to login/sign up page if they are not logged in ?

Hi Uğur ,

You can try the following code your on the onclick event:

let user = wixUsers.currentUser;
let userId = user.id;

if (wixUsers.currentUser.loggedIn) {
then code to go to payment page
}
else
wixUsers.promptLogin()
}

Hi Camille,
Thank you so much for the answer
What is the code to go to payment page?

Glad I could help…If you were using the submit option from the dataset, then you will need to remove that and add code to navigate to the page.

You will need to substitute (“/PAGEURL”) with your actual payment page’s url in the code below

Your code would look like this:

let user = wixUsers.currentUser;
let userId = user.id ;

if (wixUsers.currentUser.loggedIn) {
wixLocation.to(“/PAGEURL”);
}
else
wixUsers.promptLogin()
}

It says wixusers and wix location is not defined ?

My bad - At the very top of the code page, add the following:

import wixUsers from ‘wix-users’;

import wixLocation from ‘wix-location’;

Oh it works very well, thank you so much :slight_smile: