I did a login page. If user enters email and password then user can enter the site. But I add a jsw file to access the collection. jsw file works fine. When I invoke the function from jsw file in login page, I cannot get the result.
I tried different ways. For example;
1. login(email, password)
.then(function(result) {
if (result === true)
2. login(email, password)
.then(result {
if (result === true)
3. let isSuccessful : login(email, password);
But still does not work
My account : cihangirgeveci@hotmail.com
My site : Administr.Affair
//backend code function functionName(a,b) { return wixData.query("database") .eq("a", a) .eq("b", b) .find() .then((res) => { return (res) }) }
I think you forgot the return before wixData
the function returns boolean value. But I can not get this value from login page .
You can see the return keyword.
This is my jsw file content:
import wixData from 'wix-data'; export function login(email, password) { let isSuccessful = false; wixData.query("AccessRightToSite") .eq("email", email) .eq("password", password) .find() .then((result) => { if (result.items.length === 1) { console.log("Yes"); return true; } else { console.log("No"); return false; } }); }
This is my login page : If you look to response side below, I don't know the reason but response is null or undefined
import wixLocation from 'wix-location'; import wixWindow from 'wix-window'; import { login } from 'backend/security'; import { session } from 'wix-storage'; $w.onReady(function () { //TODO: write your page related code here... }); export function btnLogin_click(event) { let email = $w("#txtEmail").value; let password = $w("#txtPassword").value; login(email, password) .then((response) => { console.log(response); if (response === true) { wixLocation.to('/homepage'); session.setItem("email", email); session.setItem("password", password); console.log(session); console.log("successful") } else { console.log("warning") wixWindow.openLightbox("WarningMessage"); } }) }
What are you actually trying to accomplish with your additional backend jsw file?
Could you not use something already setup with the Wix Users Backend?
https://www.wix.com/corvid/reference/wix-users-backend.html