wixUsersBackend.login() not working for user validation in http-functions.js

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.

I’ve come across that “Bad Request: please check the user inputs” a couple of times, and it usually has to do with the password. Have you tried console.log them to see what they hold? Is the password between 4 and 15 chars, consisting of printable chars?

The password I’m testing with is simply letters and numbers and is 11 chars. I’ve already console.log()'d them and both fields are what is expected (I can login to the site in a web browser with the same credentials). I’m even trying sending the request via postman to make sure nothing in my app could be configured incorrectly, but I’m getting the same error. Could it be down to some encoding in the JSON body, since that’s where I’m getting the fields from?

@jacobhothersall Ok, I looked it up. I found one identical problem where the domain name extension was not supported for backend login: .studio (so someusername@somedomain.studio). Could that be it?

Don’t think so, the email I’m using is a ‘@gmail.com’ domain.

Ok strangely enough today it is working fine? Maybe something was being changed behind the scenes.