OK. My database has an Email field and FileURL field. I tried this:
import wixData from 'wix-data';
import wixLocation from 'wix-location';
import wixUsers from 'wix-users';
$w.onReady(function () {
let user = wixUsers.currentUser;
if (!user.loggedIn){
wixLocation.to('/'); //if the user is not logged in take them to the home page or could set to member only page and go to login
}
let email = user.getEmail(); // logged in user; so get email
let url = wixLocation.url; //current page url
wixData.query("OurTest")
.eq('Email', email)
.find()
.then( (results) => {
if (results.FileURL !== url)
wixLocation.to('/');
} )
.catch( () => {
wixLocation.to('/');
} );
});
I wanted to check if the FileURL set for the user with that email was not the URL of this page. If it wasn’t, I wanted to kick them out. Otherwise, I wanted the page to display. This code seems to work:
if (!user.loggedIn){
wixLocation.to('/');
}
The query, though, is mucked up. Everyone gets taken back to the login page. Can someone help me with this query or tell me where I’m going wrong?
Thanks–
Al