Search code examples
wakanda

Create a custom login in wakanda 1.1.3


I am creating a Angular2 application in which i need a custom login instead of the existing directory login So, I added the following code and created some new files and code as the following

i added a new file login.js under the backend location with the following code

directory.setLoginListener("loginFuction","Admin");

I made changes to my require.js as the following

function loginFunction(email,password){
    console.log("Call is being made to the backend");
    var u = ds.User.find("email : 1" ,email);
    console.log(u);
    if(!u){
        return false;
    }else{
        var token = currentSession.promoteWith("Admin");
        if(u.password == password){
            var theGroups = [];
            switch(u.role){
                case 'Admin':
                    theGroups.push('Admin');
                    break;
                case 'Users':
                    theGroups.push('Users');
                    break;
            }

            var connectTime = new Date();

            return {
                ID : u.ID,
                name : u.email,
                fullName : u. fullname,
                belongsTo : theGroups,
                storage:{
                    time : connectTime
                }
            };

        }else{
            return {
                error : 1024,
                errorMessage : "invalid login"
            }
        }
    }


};

when i call the loginFunction from my normal component like

this.wakanda.directory.login('[email protected]','adithya').then(res => {
        console.log(res);
    });

I am getting an error stating

EXCEPTION: Uncaught (in promise): Error: Directory.login: Unauthorized

All the table are being made global access, and everything is being made as public.

Can anyone help me with this solution.

Thanks in advance.


Solution

  • The exact method of creating the custom login in wakanda studio 1.1.3 is of the following we have to make change in the function call present in the bootstrap.js like the following

    directory.setLoginListener("loginFunction");
    

    by removing the "Admin" as the second parameter .