Cancel the login progress

During login, I am performing custom authentication, for which a loader is shown with a cancel button. If the cancel button is clicked, the Login process should be terminated.

I am able to show the loader until the login returns a success/failure state. But on click of Cancel, unable to stop the Login process.

Attaching my code snippet.

In sysauth.htm

<%- if showpopup then %>
	<div id="loader-popup" >
		<br>Authentication in progress, please wait ...
        <input type="submit" id="cancelLogin" value="Cancel" onclick="<% cancelLogin("session-id") %>">
<% end -%>

On click of cancel, I want to call the method

function cancelLogin(sid)
	ubus("session", "destroy", {
		ubus_rpc_session = sid,

My questions are,

  1. In which file the cancelLogin() should be included? (tried including in dispatcher.lua, index.lua & util.lua but the method's not getting called on click)
  2. How to terminate the running process and invoke cancelLogin()?

Any help would be appreciated.

Maybe include it in sysauth.htm, included in a <script> block. It seems you have some conceptual misunderstandings on which code runs on the server side and which one on the client side. Things like onclick events are client side JavaScript code, not server side events. Unless you implement additional measures like XHR calls, such code solely remains on the client in the form of JS code.