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 connectionState = 'OFFLINE';
|
||||
let serverVersion = '—';
|
||||
@@ -239,18 +281,7 @@
|
||||
authError = 'Login succeeded, but the session could not be stored in the Linux keyring.';
|
||||
});
|
||||
connectionState = 'CONNECTED';
|
||||
await loadActivity();
|
||||
await loadNotifications();
|
||||
await loadDiagnostics();
|
||||
await loadOAuthStatus();
|
||||
await loadCollaboration();
|
||||
await loadCollaborators();
|
||||
await loadBotCommands();
|
||||
await loadBotSecrets();
|
||||
await loadOverlays();
|
||||
await loadBackups();
|
||||
await loadStreamInfo();
|
||||
connectRealtime();
|
||||
await loadAuthenticatedData();
|
||||
if (!mustReplaceCredentials) password = '';
|
||||
if (mustReplaceCredentials) newUsername = username;
|
||||
} catch (error) {
|
||||
@@ -1065,6 +1096,7 @@
|
||||
await loadNativeSettings();
|
||||
void checkServer();
|
||||
void loadPublicCommands();
|
||||
void restoreNativeSession();
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user