Hi Yeison,
There are several answers to this question, so it would help if you provide more information on how users are accessing your application.
The most common way to ensure a user has logged in is to define an authentication method in your .xsaccess file: Enable Access to SAP HANA XS Application Packages - SAP HANA Developer Guide for SAP HANA Studio - SAP Library. When this is enabled, users will be redirected to the HANA logon page if they access your application.
If you still need to have anonymous access for your application, you can look into using a pre-defined SQLCC connection. Here's an example of that: Anonymous Call to access XSJS service using SQLCC .
Otherwise, if you want to log in to HANA using only JavaScript, I don't think I have seen this documented. Someone else may have details about this, but it may not be officially supported.