Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(api): correct token refresh endpoint in auth and user services

Steven Enamakel1b411741af6d
diff --git a/app/src/services/api/authApi.ts b/app/src/services/api/authApi.ts
index 291d92475e..b6c9912d4e 100644
--- a/app/src/services/api/authApi.ts
+++ b/app/src/services/api/authApi.ts
@@ -1,6 +1,6 @@
import { getBackendUrl } from '../backendUrl';
import { getClientVersionHeaders } from '../clientVersionHeaders';
-import { callCoreRpc } from '../coreRpcClient';
+import { loginWithToken } from '../session/sessionOwner';
const EMAIL_MAGIC_LINK_TIMEOUT_MS = 15_000;
@@ -46,18 +46,9 @@ export async function sendEmailMagicLink(
}
/**
- * Consume a verified login token and return the JWT.
- * Works for both Telegram and OAuth login tokens.
- * POST /telegram/login-tokens/:token/consume (no auth required)
+ * Consume a verified login token and install the resulting session through
+ * the session owner. Works for both Telegram and OAuth login tokens.
*/
-export async function consumeLoginToken(loginToken: string): Promise<string> {
- const response = await callCoreRpc<{ result: { jwtToken: string } }>({
- method: 'openhuman.auth.consume_login_token',
- params: { loginToken },
- });
- const jwtToken = response.result?.jwtToken;
- if (!jwtToken) {
- throw new Error('Login token invalid or expired');
- }
- return jwtToken;
+export async function loginWithLoginToken(loginToken: string): Promise<void> {
+ await loginWithToken(loginToken);
}
diff --git a/app/src/services/api/userApi.ts b/app/src/services/api/userApi.ts
index a589c21536..cc6dcff91e 100644
--- a/app/src/services/api/userApi.ts
+++ b/app/src/services/api/userApi.ts
@@ -1,15 +1,19 @@
import type { User } from '../../types/api';
-import { callCoreCommand } from '../coreCommandClient';
+import { fetchCurrentUser } from '../session/sessionOwner';
/**
* User API endpoints
*/
export const userApi = {
/**
- * Get current authenticated user information
- * Core RPC -> GET /auth/me
+ * Get current authenticated user information: a live `GET /auth/me`
+ * through the session owner (the Tauri shell on the desktop).
*/
getMe: async (): Promise<User> => {
- return await callCoreCommand<User>('openhuman.auth_get_me');
+ const current = await fetchCurrentUser(true);
+ if (!current.user) {
+ throw new Error('REJECTED: no signed-in user');
+ }
+ return current.user as User;
},
};
diff --git a/app/src/utils/tauriCommands/auth.ts b/app/src/utils/tauriCommands/auth.ts
index bed38ccb98..3826528525 100644
--- a/app/src/utils/tauriCommands/auth.ts
+++ b/app/src/utils/tauriCommands/auth.ts
@@ -1,27 +1,14 @@
/**
* Authentication commands.
+ *
+ * Session *ownership* (login-token exchange, `/auth/me`, current user) lives
+ * in `services/session/sessionOwner` — the Tauri shell on the desktop, a thin
+ * browser equivalent elsewhere. The core only reports and holds the credential
+ * (`auth.get_state`, `auth.get_session_token`, provider credentials).
*/
import { callCoreRpc } from '../../services/coreRpcClient';
-// `safeInvoke` (aliased to `invoke`) replaces bare
-// `@tauri-apps/api/core::invoke` so the CEF `window.ipc.postMessage`
-// synchronous throw (Sentry TAURI-REACT-7 / TAURI-REACT-6) surfaces as a
-// rejected Promise. `exchangeToken` runs early in the auth flow where the
-// CEF bridge can still be unwired, so this matters most.
-import { type CommandResponse, safeInvoke as invoke, isTauri } from './common';
-
-/**
- * Exchange a login token for a session token
- */
-export async function exchangeToken(
- backendUrl: string,
- token: string
-): Promise<{ sessionToken: string; user: object }> {
- if (!isTauri()) {
- throw new Error('Not running in Tauri');
- }
-
- return await invoke('exchange_token', { backendUrl, token });
-}
+import { logoutSession, storeSessionToken } from '../../services/session/sessionOwner';
+import { type CommandResponse, isTauri } from './common';
/**
* Get the current authentication state from Rust
@@ -49,36 +36,19 @@ export async function getSessionToken(): Promise<string | null> {
}
/**
- * Logout and clear session
+ * Logout and clear session.
*/
export async function logout(): Promise<void> {
- await callCoreRpc({ method: 'openhuman.auth_clear_session' });
+ await logoutSession();
}
/**
- * Store session in secure storage.
- *
- * Options:
- * - `allowPendingBackendValidation` -- skip backend `/auth/me` proof and persist
- * the session with a deferred-validation marker.
- * - `timeoutMs` -- per-call timeout (default 30s, clamped [1s, 10min]).
- * Use a shorter value (e.g. 10s) when the caller will retry after a timeout
- * rather than hang for the full default.
+ * Install a session token through the session owner. A backend JWT is
+ * validated against `/auth/me` by the owner before the core stores it; a
+ * local (`.local`) token is stored as-is with `user`.
*/
-export async function storeSession(
- token: string,
- user: object,
- options?: { allowPendingBackendValidation?: boolean; timeoutMs?: number }
-): Promise<void> {
- await callCoreRpc({
- method: 'openhuman.auth_store_session',
- params: {
- token,
- user,
- ...(options?.allowPendingBackendValidation ? { allowPendingBackendValidation: true } : {}),
- },
- timeoutMs: options?.timeoutMs,
- });
+export async function storeSession(token: string, user: object): Promise<void> {
+ await storeSessionToken(token, user);
}
export async function openhumanEncryptSecret(plaintext: string): Promise<CommandResponse<string>> {