native: fix token passtrough

This commit is contained in:
Johannes Jöns 2024-07-11 15:14:23 +02:00
parent 8f9eb24c23
commit 7ac6d2adde
2 changed files with 15 additions and 3 deletions

View file

@ -86,7 +86,7 @@ Rectangle {
xhr.onreadystatechange = function() { xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) { if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) { if (xhr.status === 200) {
var token = xhr.responseText.trim(); // Trim to remove any leading/trailing whitespace var token = xhr.responseText;
loginSuccess(token); loginSuccess(token);
} else { } else {
console.log("Login failed: " + xhr.status); console.log("Login failed: " + xhr.status);

View file

@ -32,7 +32,7 @@ Window {
id: loginPageComponent id: loginPageComponent
LoginScreen { LoginScreen {
onLoginSuccess: function(token) { onLoginSuccess: function(token) {
authToken = token; root.authToken = token;
stackView.push(mainPageComponent); stackView.push(mainPageComponent);
} }
} }
@ -41,10 +41,22 @@ Window {
Component { Component {
id: mainPageComponent id: mainPageComponent
MainPage { MainPage {
authToken: authToken id: mainPage
authToken: root.authToken
onLogout: { onLogout: {
stackView.push(loginPageComponent) stackView.push(loginPageComponent)
} }
Component.onCompleted: {
// Update authToken when MainPage is created
authToken = root.authToken;
}
}
}
onAuthTokenChanged: {
if (stackView.currentItem && stackView.currentItem.authToken !== undefined) {
stackView.currentItem.authToken = authToken;
} }
} }
} }