diff --git a/native/LoginScreen.qml b/native/LoginScreen.qml index 01d9da0..b3d7e28 100644 --- a/native/LoginScreen.qml +++ b/native/LoginScreen.qml @@ -71,25 +71,27 @@ Rectangle { text: qsTr("Submit") - onClicked: { - var xhr = new XMLHttpRequest(); - xhr.open("POST", "https://api.clan-war.net/api/v1/auth/login"); - xhr.setRequestHeader("Content-Type", "application/json"); - xhr.onreadystatechange = function() { - if (xhr.readyState === XMLHttpRequest.DONE) { - if (xhr.status === 200) { - var token = xhr.responseText.trim(); // Trim to remove any leading/trailing whitespace - loginSuccess(token); - } else { - console.log("Login failed: " + xhr.status); - } + onClicked: login + } + + function login() { + var xhr = new XMLHttpRequest(); + xhr.open("POST", "https://api.clan-war.net/api/v1/auth/login"); + xhr.setRequestHeader("Content-Type", "application/json"); + xhr.onreadystatechange = function() { + if (xhr.readyState === XMLHttpRequest.DONE) { + if (xhr.status === 200) { + var token = xhr.responseText.trim(); // Trim to remove any leading/trailing whitespace + loginSuccess(token); + } else { + console.log("Login failed: " + xhr.status); } } - var data = JSON.stringify({ - email: nameT.text, - password: passwordT.text - }); - xhr.send(data); } + var data = JSON.stringify({ + email: nameT.text, + password: passwordT.text + }); + xhr.send(data); } } diff --git a/native/Main.qml b/native/Main.qml index ca58216..cc4bd1d 100644 --- a/native/Main.qml +++ b/native/Main.qml @@ -31,9 +31,9 @@ Window { Component { id: loginPageComponent LoginScreen { - onLoginSuccess: { - authToken = token - stackView.push(mainPageComponent) + onLoginSuccess: function(token) { + authToken = token; + stackView.push(mainPageComponent); } } }