Hi there,
You can also have a password lightbox on your website, and prompt your users to enter the password the first time they land on your website, it may not be as instantaneous as the actual login, as it is unlike the actual login, it runs after the page has finished loading.
The lightbox will be opened each and every time your visitors navigate to a page, that’s why we need to remember that the user has entered the password once, and not to ask for it again, we can do that using the session storage .
This code needs to run on all pages - the ( masterPage.js ) file.
import wixLocation from 'wix-location';
import wixWindow from 'wix-window';
import { session } from 'wix-storage';
$w.onReady(() => {
if (wixLocation.path[0] !== 'protected-content') {
const cache = session.getItem('auth');
if (typeof cache === 'string') {
const auth = JSON.parse(cache);
if (!auth.authenticated) { propmpt_password() }
} else {
propmpt_password();
}
}
})
function propmpt_password() {
wixWindow.openLightbox('Check Password').then((authenticated) => {
if (authenticated) {
// Save the authentication
session.setItem('auth', JSON.stringify({ authenticated }));
} else {
wixLocation.to('/protected-content');
}
})
}
To learn how to set up the lightbox with password protection, check out my answer on this thread.
Hope this helps~!
Ahmad