Custom code login help needed

I’ve implemented biometric login for my app, and need help with the JS code to use to log a user in and redirect them to the correct page.

The custom code I’m using looks like this

And I need to add the login code on line 18. I have tried using the code in this article

But I get this problem

Can you help me with the right code to access the login API and redirect the user?

Hi, @Luc_Zentar !

If I understand correctly, you are trying to use Java code instead of JavaScript. From the link you provided, select the JavaScript tag and try to use that code example.

Yurii Zaripa.

Thank you @Yurii_Zaripa, sorry that’s an easy mistake!

I have added the JS script, and it’s still not working

Will the problem be with line 18? Do I need to do something else to import backendless?

Hi @Luc_Zentar,

did you install the backendless npm package first? I mean running npm i backendless on your server side.

Hi @stanislaw.grin I don’t think so, I am using Backendless hosting so how would I do that?

Do you mean you are using the Custom Code block in the UI Builder?

If so, try to remove the 18th line, since there already exists a global variable Backendless. Please let me know if that helps

Thank you @stanislaw.grin that has worked.

The only problem I have now is that the user is logged in but doesn’t progress to the page that follows the login process. So they just see the same login page and don’t know they have been logged in.

is there something I can add to direct them to a new page?

Thank you!

Hello @Luc_Zentar
I think Backendless.initApp is not required too. Ui-Builder does it on his own
To do redirect, you should enrich “onSuccess login function”

const onSuccess = user => {
   const pageName = 'nextPageName'
   const pageData = { logedUser: user } 

   BackendlessUI.Navigator.goToPage(pageName, pageData)

Page Data is no required

const onSuccess = user => {
   const pageName = 'nextPageName'




I have been testing more and have found a further issue.

The biometric login works and the user is sent to the next page. But when accessing the app menu, which re-directs the user to another URL within the webview in the app, the user is then logged out and returned to the biometric login page.

This issue does not happen when a user logs in using email, so something is different using the custom code which is causing this problem. Can you help with what that might be?

When a user logs in using email, the login block has ‘stay loged’ option?

If so, update 38 line on the screenshoot to:
Backendless.UserService.login(username, password, true);

Perfect, thank you!