Appery.io login plugin does not work!

Hi!
I have created a database and imported register and login plugins from Apper.io to register and login users in my database. The register function works fine, but the login simply does not work. I have not been able to figure out why and could not figure out how to troubleshoot the java script.

The only error I am getting is from the "catch" function in the end of the script saying that the username or password is incorrect, which it is not. I have triple checked that the registration is stored in the database and that my input is correct. Any help here is highly appreciated!

Code:
var databaseId = "I have copied the database API key here";
var username = request.get("username");
var password = request.get("password");

try {
// User login
var userLoginInfo = DatabaseUser.login(databaseId, username, password);

// Retrieve any additional information from UserProfile collection
// linked from the Users collection
var userProfile = DatabaseUser.retrieve(databaseId, userLoginInfo._id, "toProfile", userLoginInfo.sessionToken);

var userData = {
"session": userLoginInfo.sessionToken,
"username": userProfile.username,
"email": userProfile.toProfile.email,
"country": userProfile.toProfile.country
};

response.success(userData, "application/json");

} catch (error) {
response.error({
"message": "Incorrect username or password."
}, 400);
}
1 person has
this question
+1
Reply
  • Eirik,

    can you change your code as follows please ( please copy the code from here into your server code and replace it....make a backup of your existing script PRIOR to doing this by downloading a copy of it.....):

    var databaseId = "I have copied the database API key here";
    var username = request.get("username");
    var password = request.get("password");
    console.log('The Inbound Parameters for username and password are:' , username, ' / ' , password ) ;

    try {
    // User login
    var userLoginInfo = DatabaseUser.login(databaseId, username, password);

    // Retrieve any additional information from UserProfile collection
    // linked from the Users collection
    var userProfile = DatabaseUser.retrieve(databaseId, userLoginInfo._id, "toProfile", userLoginInfo.sessionToken);

    var userData = {
    "session": userLoginInfo.sessionToken,
    "username": userProfile.username,
    "email": userProfile.toProfile.email,
    "country": userProfile.toProfile.country
    };

    response.success(userData, "application/json");

    } catch (e) {
    console.log( '[JS-INFO] Error from server code: ' , e.message )
    response.error({
    "message": "Incorrect username or password."
    }, 400);
    }

    ============================================

    Please then go to the trace tab after running it - and advise (copy and paste back here) what's on the trace tab (Scroll down).

    Best wishes,

    Bruce
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. indifferent, undecided, unconcerned happy, confident, thankful, excited kidding, amused, unsure, silly sad, anxious, confused, frustrated