Hi All,
I am trying to create a login which is for a job search site, which means that either people log in as a job seeker, or business to post jobs. In my signup & login forms I am trying to get the email, and split the domain out, to see if it matches other users from the same business. They can then see the correct data as a user/business.
I’m not sure if this is the best way to do this. Maybe others have this business/user login already and have another method.
I have created the below code, but I am getting the error " Property ‘hasSomePermissions’ does not exist on type ‘WixDataQuery’.
Here is my code:
//Signup
import wixUsers from 'wix-users';
import wixData from 'wix-data';
import wixLocation from 'wix-location';
$w.onReady(function () {
// Handle the login form submission.
$w('#button2').onClick(async () => {
const fName = $w('#input4');
const lName = $w('#input3')
const email = $w('#input2').value;
const password = $w('#input1').value;
try {
// Log in the user with Wix Users.
await wixUsers.login(email, password);
// Redirect the user to the appropriate page based on their role.
const user = await wixUsers.currentUser;
if (user.role === 'Business') {
// Set up permissions for the business collection so that only logged-in businesses can view and edit their own information.
wixData.query('Jobs')
.find()
.then((results) => {
results.setPermissions(wixData.PERMISSIONS_TYPE.MEMBER_AUTHENTICATED, wixData.filter().eq('domain', wixUsers.currentUser.getEmail().split('@')[1]));
})
.catch((error) => {
console.error(error);
});
wixLocation.to('/business-dashboard');
} else if (user.role === 'Customer') {
wixLocation.to('/customer-dashboard');
}
} catch (error) {
// Handle login errors.
console.error(error);
$w('#text24').show();
}
});
});
//Login
import wixUsers from 'wix-users';
import wixData from 'wix-data';
import wixLocation from 'wix-location';
$w.onReady(function () {
// Handle the login form submission.
$w('#submit').onClick(async () => {
const email = $w('#email').value;
const password = $w('#password').value;
try {
// Log in the user with Wix Users.
await wixUsers.login(email, password);
// Get the user's email domain.
const currentUser = await wixUsers.currentUser;
const domain = currentUser.getEmail().split('@')[1];
// Check if the user's domain is associated with a company.
const company = await wixData.query('Companies')
.eq('domain', domain)
.find();
if (company.items.length > 0) {
// Set the user's permissions to access the jobs collection.
const permissions = wixData.filter()
.eq('_id', company.items[0].jobsCollection)
.hasSomePermissions(wixData.PERMISSIONS_TYPE.MEMBER_AUTHENTICATED);
await wixUsers.currentUser.setPermissions(permissions);
// Redirect the user to the appropriate page based on their role.
if (currentUser.role === 'Business') {
wixLocation.to('/blank-3');
} else if (currentUser.role === 'Customer') {
wixLocation.to('/blank-4');
}
} else {
// Handle the case where the user's domain is not associated with a company.
console.error('User is not associated with a company');
$w('#generalErrMsg').show();
}
} catch (error) {
// Handle login errors.
console.error(error);
$w('#generalErrMsg').show();
}
});
} );