Empty "Get Current User" on beforeRegister Codeless event

Hi,

Please refer to post since it is related.

I am trying this, but for some reason the “Get current user” function is returning null, even though I logged in first before calling the Register function.

I am calling the Register function via Javascript.
I also called Backendless.UserService.getCurrentUser() just before calling the Register function to confirm that I am logged in and I do get a result, but the “Get current user” function still returns null on the event.

Any reason why this would be?

Hello @Bennie_Matthee,

currentUser is a result of the Login function, not the Register one.
Could you please provide your APP ID?

Regards,
Olha

Hi Olha,

Thank you for your response.

My App ID is 0524F6F0-3AAC-4895-FFC0-7DBA231B8C00

Im not sure if I am making myself clear enough.
Below is my Codeless Block.

When I run this code in Javascript I always get the thrown error “No Logged in User Found” and when I check the RealTime Logs then the “Get current user” block object is null.

function userLoggedIn(user) {
console.log(“user has logged in”);
console.log(user);

Backendless.UserService.getCurrentUser()
.then(function (currentUser) {
console.log(“currentUser”);
console.log(currentUser);
var Newuser = new Backendless.User();
Newuser.email = “simple@email.com”;
Newuser.password = “123456789”;
Backendless.UserService.register(Newuser).then(userRegistered).catch(gotError);
})
.catch(function (error) {
console.log(“getCurrentUser error”);
console.log(error);
});
}

function gotError(err) // see more on error handling
{
console.log("error message - " + err.message);
console.log("error code - " + err.statusCode);
}

var login = “admin@email.com”;
var password = “123456789456123”;
Backendless.UserService.login(login, password)
.then(userLoggedIn)
.catch(gotError);

Ideally I wanted the Admin users to Register users first, but I think I will change my strategy.

Currently I have a Members table which will get loaded with Members by the Admins.
We would then send an invite to the member to Register.
I will then use the beforeRegister event and check if the Registering email address exist in the Members table first and then allow the Register procedure.

Hi @Bennie_Matthee,

it looks like a bug on our side. I have created an internal ticket with ID BKNDLSS-23373 to investigate this issue. We’ll let you know once we have any news.

Regards,
Stanislaw

Hi,

Thank you for your response.
Always good to kill some bugs. :slight_smile:

1 Like