Skip to content

Commit c24162f

Browse files
tofikwestclaude
andcommitted
fix(device-agent): encode redirect params + make performLogout self-contained
- URL-encode code and state in device-callback redirect - Move clearAuth() into performLogout so logout is self-contained - Remove redundant clearAuth() calls from all call sites in index.ts Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5eab496 commit c24162f

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

apps/portal/src/app/(public)/auth/device-callback/page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ export default function DeviceCallbackPage() {
4747
const { code } = await response.json();
4848

4949
// Redirect to the device agent's localhost server
50-
window.location.href = `http://localhost:${port}/auth-callback?code=${code}&state=${state}`;
50+
window.location.href = `http://localhost:${port}/auth-callback?code=${encodeURIComponent(code)}&state=${encodeURIComponent(state!)}`;
51+
5152
setStatus('success');
5253
} catch (err) {
5354
console.error('Device auth callback failed:', err);

packages/device-agent/src/main/auth.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type {
1010
StoredAuth,
1111
} from '../shared/types';
1212
import { log } from './logger';
13-
import { getPortalUrl, setAuth } from './store';
13+
import { clearAuth, getPortalUrl, setAuth } from './store';
1414

1515
/** How long to wait for the user to complete login in the browser */
1616
const LOGIN_TIMEOUT_MS = 5 * 60 * 1000; // 5 minutes
@@ -299,8 +299,8 @@ function errorPage(message: string): string {
299299
}
300300

301301
/**
302-
* Sign out: clear stored auth (no more Electron session cookies to manage)
302+
* Sign out: clear stored auth data
303303
*/
304304
export async function performLogout(): Promise<void> {
305-
// Nothing to clean up — stored auth is cleared by the caller via clearAuth()
305+
clearAuth();
306306
}

packages/device-agent/src/main/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
startScheduler,
1515
stopScheduler,
1616
} from './scheduler';
17-
import { clearAuth, getAuth, getLastCheckResults } from './store';
17+
import { getAuth, getLastCheckResults } from './store';
1818
import {
1919
createTray,
2020
destroyTray,
@@ -64,7 +64,6 @@ setSessionExpiredHandler(async () => {
6464
log('Session expired — clearing auth and prompting re-login');
6565
stopScheduler();
6666
await performLogout();
67-
clearAuth();
6867
currentResults = [];
6968
setStatus('unauthenticated');
7069
notifyRenderer(IPC_CHANNELS.AUTH_STATE_CHANGED, false);
@@ -77,7 +76,6 @@ setDevicesNotFoundHandler(async () => {
7776
log('All devices returned 404 — clearing auth and re-registering');
7877
stopScheduler();
7978
await performLogout();
80-
clearAuth();
8179
currentResults = [];
8280
setStatus('unauthenticated');
8381
notifyRenderer(IPC_CHANNELS.AUTH_STATE_CHANGED, false);
@@ -128,7 +126,6 @@ const trayCallbacks = {
128126
log('User signing out');
129127
stopScheduler();
130128
await performLogout();
131-
clearAuth();
132129
currentResults = [];
133130
setStatus('unauthenticated');
134131
notifyRenderer(IPC_CHANNELS.AUTH_STATE_CHANGED, false);
@@ -179,7 +176,6 @@ ipcMain.handle(IPC_CHANNELS.LOGOUT, async () => {
179176
log('Logout via IPC');
180177
stopScheduler();
181178
await performLogout();
182-
clearAuth();
183179
currentResults = [];
184180
setStatus('unauthenticated');
185181
notifyRenderer(IPC_CHANNELS.AUTH_STATE_CHANGED, false);

0 commit comments

Comments
 (0)