I have missed the opportunity to lock down my sites during development. I still need to publish the sites so that the client can see and try out the site. But I am always scared it will be found in someway by search engines or just tested by none approved testers.
So I decided to make the small code that takes the problem away and here you have it.
Open your code editor, place yourself in the Site Code Tab and paste in the following snippet there.
import wixUsers from 'wix-users';
$w.onReady(function () {
let user = wixUsers.currentUser;
console.log(user);
if (user.role === "Visitor")
{
let options = {"mode": "login", "lang": "se"};
wixUsers.promptLogin(options)
.then( (user) => {
let userId = user.id; // "r5me-6fem-45jf-djhe-484349"
let isLoggedIn = user.loggedIn; // true
let userRole = user.role; // "member"
return user.getEmail();
} )
.then( (email) => {
let userEmail = email; // "user@something.com"
} )
.catch( (err) => {
let errorMsg = err; // "The user closed the login dialog"
} );
}
});
This code will make sure no visitors can view your site and they will be prompted to login asap. If you want to extend the code to check if they are Member, Admin go ahead. I just need to protect it from visitors.
Don’t forget to set your language in the options above.
Article: https://www.wixsweden.se/password-protect-site
1 Like
Wouldn’t member protecting all pages fix this though? Remove the auto approve and simply have a "blank landing page that requires login to view the actual testing site?
And removing the “let it be found” on each tab setting.
(Not that u need this .,… I give the URL on everything I test since I use it for video purposes on Wix Community channel)
I was just simply curious why/if the above wouldn’t work.
When I develop a client site with like 75 pages it is problematic because I have to then unlock all the pages again when it is time for publishing. If it would be possible to password protect a whole site with ease it would be great but this functions do not exist today. That’s why I did this.
There is a problem though with the social login which I can’t figure out.
I get you …
But for me … I think 75 clicks of taking off member page protection is much easier than coding … Lol
If I was better at the coding … I’m sure I would have the opposite point of view 
Plus… I’m going to “be” on those pages ANYWAY before I publish as I make sure everything is good and clear on each page. Might as well click member page on or off as I finish checking the page … This way way I know which pages I have and have not already audited before going live 
I am efficient and OCD like that … 




We are all different I am a coder on want to rely on code but I am becoming more and more a non coder thanks to Wix and I like it.
What software do you use when recording your videos.
UPDATE: When the user closes the login dialog the page will be shown for everyone. You will have to redirect them using the wix-location API to your startpage to make the dialog trigger again.
$w.onReady(function () {
let user = wixUsers.currentUser;
console.log(user);
if (user.role === "Visitor")
{
let options = {"mode": "login", "lang": "sv"};
wixUsers.promptLogin(options)
.then( (user) => {
let userId = user.id; // "r5me-6fem-45jf-djhe-484349"
let isLoggedIn = user.loggedIn; // true
let userRole = user.role; // "member"
return user.getEmail();
} )
.then( (email) => {
let userEmail = email; // "user@something.com"
} )
.catch( (err) => {
wixLocation.to("https://andreaskviby.wixsite.com/woorocks/");
} );
}
});
I use Screencast-O-Matic (Premium plan) to record
I don’t know how much I could possibly bring to the plate, but I would love to swap ideas with you … maybe you could help me with some code stuff? I’m a fast learn … I just ask a lot of questions. 
I am always here to swap ideas regarding the WIX platform.