Restore native client sessions
This commit is contained in:
+44
-12
@@ -31,6 +31,48 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function loadAuthenticatedData() {
|
||||||
|
await loadActivity();
|
||||||
|
await loadNotifications();
|
||||||
|
await loadDiagnostics();
|
||||||
|
await loadOAuthStatus();
|
||||||
|
await loadCollaboration();
|
||||||
|
await loadCollaborators();
|
||||||
|
await loadBotCommands();
|
||||||
|
await loadBotSecrets();
|
||||||
|
await loadOverlays();
|
||||||
|
await loadBackups();
|
||||||
|
await loadStreamInfo();
|
||||||
|
connectRealtime();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function restoreNativeSession() {
|
||||||
|
if (!nativeClientAvailable() || !username || !serverAddress) return;
|
||||||
|
try {
|
||||||
|
const settings: ClientSettings = { server_address: serverAddress, username };
|
||||||
|
const storedSession = await invoke<string | null>('load_server_session', { settings });
|
||||||
|
if (!storedSession) return;
|
||||||
|
const response = await fetch(`${serverAddress}/api/v1/auth/session`, {
|
||||||
|
headers: { authorization: `Bearer ${storedSession}` },
|
||||||
|
});
|
||||||
|
if (!response.ok) {
|
||||||
|
await invoke('clear_server_session', { settings });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result: { must_replace_credentials: boolean } = await response.json();
|
||||||
|
sessionToken = storedSession;
|
||||||
|
authenticated = true;
|
||||||
|
mustReplaceCredentials = result.must_replace_credentials;
|
||||||
|
connectionState = 'CONNECTED';
|
||||||
|
await loadAuthenticatedData();
|
||||||
|
if (mustReplaceCredentials) newUsername = username;
|
||||||
|
} catch {
|
||||||
|
// A stale keyring session must not prevent the normal login form from opening.
|
||||||
|
sessionToken = '';
|
||||||
|
authenticated = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let serverAddress = 'http://127.0.0.1:8787';
|
let serverAddress = 'http://127.0.0.1:8787';
|
||||||
let connectionState = 'OFFLINE';
|
let connectionState = 'OFFLINE';
|
||||||
let serverVersion = '—';
|
let serverVersion = '—';
|
||||||
@@ -239,18 +281,7 @@
|
|||||||
authError = 'Login succeeded, but the session could not be stored in the Linux keyring.';
|
authError = 'Login succeeded, but the session could not be stored in the Linux keyring.';
|
||||||
});
|
});
|
||||||
connectionState = 'CONNECTED';
|
connectionState = 'CONNECTED';
|
||||||
await loadActivity();
|
await loadAuthenticatedData();
|
||||||
await loadNotifications();
|
|
||||||
await loadDiagnostics();
|
|
||||||
await loadOAuthStatus();
|
|
||||||
await loadCollaboration();
|
|
||||||
await loadCollaborators();
|
|
||||||
await loadBotCommands();
|
|
||||||
await loadBotSecrets();
|
|
||||||
await loadOverlays();
|
|
||||||
await loadBackups();
|
|
||||||
await loadStreamInfo();
|
|
||||||
connectRealtime();
|
|
||||||
if (!mustReplaceCredentials) password = '';
|
if (!mustReplaceCredentials) password = '';
|
||||||
if (mustReplaceCredentials) newUsername = username;
|
if (mustReplaceCredentials) newUsername = username;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -1065,6 +1096,7 @@
|
|||||||
await loadNativeSettings();
|
await loadNativeSettings();
|
||||||
void checkServer();
|
void checkServer();
|
||||||
void loadPublicCommands();
|
void loadPublicCommands();
|
||||||
|
void restoreNativeSession();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user