I’ve looked through pages of the forum and have spent days trying to figure out work arounds, but I cannot find solutions to these two key points regarding log in and sign up:
I am trying to do a query at log in to see if a field (boolean) is checked (true) or not (false). I feel like the coding is similar to:
// prompt the user to log in
wixUsers.promptLogin( {“mode”: “login”} )
.then( (user) => {
userId = user.id;
return user.getEmail();
} )
.then( (email) => {
// check if there is an item for the user in the collection
userEmail = email;
return wixData.query(“Profile”)
.eq(“_id”, userId)
.find();
} )
but how do you add another parameter to the query so that only certain members can log in? Esentially, customers sign up and pay using intergrated Stripe account, and that updates in my “Members” collection as a “PaidMember” boolean fieldtype. So when the member logs in, the email must match (as already shown in code) as well as the “PaidMember” must be checked. If there’s a better way to validate members to log in, please let me know.
Concerning the Sign Up prompt, is there a way to edit the success message, link to my Create Account page, or ideally, bypass the sign up prompt and link to the page directly? I tried it on the backend in the routers.js with:
import wixLocation from ‘wix-location’;
export function membersignup_customizeQuery() {
wixLocation.to(/createaccount/);
}
If possible, the “Sign up” button would navigate to my /createaccount/ page. Or at least once the person registers their email and password on the next prompt and clicks OK, and would navigate then. I’ve tried wixLocation.to but it isn’t working, but I may be placing it in the wrong place.
In summary, my objective is to only allow members that have their “email” valid AND “PaidMember” checked in my Member Collection Database. Users who do not have either or sign up from the Prompt are redirected to /createaccount/ to fill out their information and pay there.
It’s only blocking users that have not paid from logging in. Anyone can log in and have access to the members only area, but I need to filter those that have actually paid to access that area.
1.) User>signs up>creates and pays for account>becomes member>has access.
2.)User>signs up>does not create account>has member login>has access.
Scenario 2 is what I’m trying to prevent. The goal is to have instant access when someone pays and signs up, instead of waiting to be approved, but currently people do not need to pay once they sign up on the prompt.
You could let all users to log in. However, for users that didn’t pay show a message that explains why they don’t see content and a button, or any other “call to action” for paying.
Use the database hooks to enable content to users who paid.
I have a similar function on my website. Instead of doing this " wixLocation.to (/createaccount/); " in the backend in the routers.js, I do it right in the page code where you have
.then( (email) => {
// check if there is an item for the user in the collection
userEmail = email;
return wixData.query(“Profile”)
.eq(“_id”, userId)
.find();
} )
Is “Profile” the name of your member’s collection? If so, you’re on the right track. Assuming you create a new record in “Profile” when a paid member fills out your “createaccount” page… try this…
let userId;
let userEmail;
// prompt the user to log in
wixUsers.promptLogin({
"mode": "signup"
})
.then((user) => {
userId = user.id;
return user.getEmail();
})
.then((email) => {
// check if an applicant
userEmail = email;
// check if there is an item for the user in the collection
//userEmail = email;
return wixData.query("Profile")
.eq("_id", userId)
.find();
})
.then((results) => {
// if an item for the user is not found
console.log("member record: " + JSON.stringify(results));
if (results.items.length === 0) {
wixLocation.to(`/sign-up`);
//wixUsers.logout();
} else {
wixLocation.to(`/createaccount`);
} //close else
}) //close .then
.catch((err) => {
console.log(err);
});
This will still create a wix contact for everybody that tries to sign up, paid or not, but this way, only paid members gets to go to your createaccount page and add themselves to your profile collection.
I have experience coding in other languages but javascript and Wix code are new for me… but hopefully that helps!
I am debugging a problem that only shows up when a user isn’t logged in. When I’m in the editor, of course I’m logged in. I can see debugging messages in the console. But when I’m logged out, I can’t be in the editor. Is there a mechanism for debugging problems for users that aren’t logged in?