Hello everyone.
I’m using Wix Editor on Windows. I want to build a custom login form using a regular page, instead of the LIghtbox Login form offered by Wix.
The login in is not happening successfully and I can’t figure out why. A bit of help would be super appreciated.
The end result of this code is: “Member is not logged in” and there is no redirection
The desired end result would be “Member is logged in” and then redirect to /newclaim
This is the code for the back-end function used for the login:
import wixMembersBackend from 'wix-members-backend';
export function kinkiLogin(email, password) {
let data = {};
return wixMembersBackend.authentication.login(email, password)
.then((sessionToken) => {
data.token = sessionToken;
data.approved = true;
return data;
})
.catch((error) => {
data.original = error;
data.errCode = error.details.applicationError.code;
data.errText = error.details.applicationError.description;
data.token = undefined;
data.approved = false;
if(error.details.applicationError.code === '-19999') {
data.errReason = 'email not found';
}
if(error.details.applicationError.code === '-19956') {
data.errReason = 'member blocked';
}
return data;
});
}
And this is the front-end code:
import { kinkiLogin } from 'backend/kinkiLoginFile.jsw';
import { authentication } from 'wix-members-frontend';
import wixLocationFrontend from 'wix-location-frontend';
// Top-level listener for login
authentication.onLogin(async (member) => {
wixLocationFrontend.to('/newclaim');
});
$w.onReady(function () {
kinkiLogin('example.email@gmail.com', 'example.password') // I write here the correct email and password manually for testing purposes
.then(() => {
// Successful login actions
const isLoggedIn = authentication.loggedIn();
if (isLoggedIn) {
console.log('Member is logged in');
} else {
console.log('Member is not logged in');
}
})
.catch((err) => {
console.error(err);
$w('#errorMessage').text = "Login failed: " + err.message;
});
});