Registration works but doesn't login (when "Only allow backend calls for Signup and Login APIs" enabled)
please help!
Here is the Backend code:
import wixUsersBackend from 'wix-users-backend';
export function registerUser(name, email, password) {
return wixUsersBackend.register(email, password, {
contactInfo: {
firstName: name
}
});
}
export function loginUser(email, password) {
return wixUsersBackend.login(email, password);
}
& here is the frontend code:
import { registerUser, loginUser } from 'backend/auth';
import wixLocation from 'wix-location';
import wixWindow from 'wix-window';
$w.onReady(function () {
// Hide the error messages initially
$w('#signupErrorMessage').hide();
$w('#loginErrorMessage').hide();
// Attach event handler to signup button
$w('#signupButton').onClick(() => {
const name = $w('#nameInput').value;
const email = $w('#emailInput').value;
const password = $w('#passwordInput').value;
if (name && email && password) {
registerUser(name, email, password)
.then(() => {
wixLocation.to('/');
})
.catch((err) => {
let errorMessage = "Error signing up. Please try again.";
if (err.message) {
errorMessage = err.message;
}
$w('#signupErrorMessage').text = errorMessage;
$w('#signupErrorMessage').show();
});
} else {
$w('#signupErrorMessage').text = "Please enter name, email, and password.";
$w('#signupErrorMessage').show();
}
});
// Attach event handler to login button
$w('#loginButton').onClick(() => {
const email = $w('#loginEmailInput').value;
const password = $w('#loginPasswordInput').value;
if (email && password) {
loginUser(email, password)
.then(() => {
wixLocation.to('/');
})
.catch((err) => {
let errorMessage = "Error logging in. Please try again.";
if (err.message) {
errorMessage = err.message;
}
$w('#loginErrorMessage').text = errorMessage;
$w('#loginErrorMessage').show();
});
} else {
$w('#loginErrorMessage').text = "Please enter both email and password.";
$w('#loginErrorMessage').show();
}
});
// Attach event handler to signup link
$w('#signupLink').onClick(() => {
wixWindow.openLightbox('SignupLightbox'); // Replace 'SignupLightbox' with the ID of your signup lightbox
});
// Attach event handler to login link
$w('#loginLink').onClick(() => {
wixWindow.openLightbox('LoginLightbox'); // Replace 'LoginLightbox' with the ID of your login lightbox
});
});
if you take money to answer, please give me a link.