auth.json) in the platform-specific app data directory — not the OS keyring. On Windows this is %APPDATA%\com.Trueears\auth.json; on Linux/macOS it is ~/.Trueears/auth.json.
TypeScript interfaces
OAuth flow
start_google_login initiates the following flow:
- Reads
GOOGLE_CLIENT_IDfrom the environment. - Constructs a Google OAuth 2.0 authorization URL (scopes:
openid email profile). - Opens the URL in the user’s default browser.
- Starts a local HTTP callback server on port
8585to receive the authorization code. - Exchanges the authorization code for access and refresh tokens via the Trueears API server (
API_URL/auth/google). - Stores the tokens and user profile in
auth.jsonon disk. - Emits
auth-success(withUserInfopayload) orauth-error(with error string) to all windows.
The
GOOGLE_CLIENT_ID environment variable must be set in .env at the workspace root. Without it, start_google_login will throw an error. The API_URL defaults to https://trueears-backend.vercel.app.start_google_login
Opens the Google OAuth consent screen in the default browser and starts the local callback server.
Returns
Promise<void> — Resolves when the browser has been opened and the callback server has started. The actual authentication result arrives asynchronously via auth-success or auth-error events.
get_auth_state
Returns the current authentication state by reading tokens and user info from the local auth file.
Returns
Promise<AuthState>
true if a valid access token and user info are present in the local auth file.The stored user profile, or
null if not authenticated.get_user_info
Retrieves the stored user profile from the local auth file without verifying token validity.
Returns
Promise<UserInfo | null> — The stored UserInfo, or null if no auth file exists.
get_access_token
Retrieves the stored access token from the local auth file.
Returns
Promise<string | null> — The stored access token string, or null if no auth file exists or the file cannot be parsed.
logout
Clears the stored tokens and user data by deleting the local auth file. Optionally revokes the refresh token on the API server.
Returns
Promise<void>
Behavior
- Sends a POST to
API_URL/auth/logoutwith the refresh token (best-effort — ignored if the request fails). - Deletes the local
auth.jsonfile.
