Hi, I have made a HTTP function that I can make an API call to in order to check a user’s authenticity via a client app. Previously I had used the wixUsersBackend module in order to call login(), if the call succeeds and my .then() block is reached I know that the user is valid.
Since then I had changed this to check a collection for an email and password hash, although this isn’t really a valid solution as when a user’s password is changed there is no way of hooking into anything to update the hash in the collection. Therefore I’m trying to go back to my previous method of using login(). I know that certain parts of wixUsersBackend do not work with http-functions.js, such as getting a current user etc, however from what I remember I was able to use wixUsersBackend.login() just fine. Now when I try to use it I get the error: “Bad Request: please check the user inputs.” and the .then() block is never reached. I know that this works previously as I had made a post here asking about using currentUser, and in the thread I made it clear I could already use wixUsersBackend.login(): https://www.wix.com/velo/forum/coding-with-velo/currentuser-not-working-from-backend-code
This is what my code looks like:
export function post_checkClient(request) {
let options = {
"headers": {
"Content-Type": "application/json"
}
};
return request.body.json()
.then( (body) => {
let email = body.email.toLowerCase();
let password = body.pass;
if (email === undefined || password === undefined) {
options.body = {
"error": "Need an email and password."
};
return badRequest(options);
}
return wixUsersBackend.login(email, password).then( () => {
//UNREACHABLE
})
.catch( (loginErr) => {
console.log(loginErr); //here is where I get the "Bad Request" error
options.body = {
"error": "Invalid login."
};
return forbidden(options);
});
.catch (() => {
options.body = {
"error": "Couldn't extract data from request body."
};
return badRequest(options);
});
}
Has something changed since the last time I tried using wixUsersBackend.login() (around Dec 2020), or am I simply missing something. Thanks.