Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,14 @@ lapses - never for one that lapsed before launch, and never across a sign-out. S
also carry `kind=mock` and a per-session `client_session_id`, which the backend uses only to label
and group its ledger rows.

### Billing and the password live on the website

**The app shows the plan; the website's account area manages the account.** `/payment` is the current plan and the three pass cards, with prices from `GET /payment/subscription-plans`, and *Choose* / *Extend* opens the website's checkout for that pass. Payment history, payment status and the password change are on the website too: the app's own checkout, history and status tabs and its change-password form are gone, because two copies drifted and every checkout change was a client release (and, on macOS, a notarization). Signing in, the plan status, the low-balance and expiry warnings and the interview profile stay here, since they are what using the app needs.

Every link out goes through `webAccountService.open()` ([web-account.service.ts](src/main/services/web-account.service.ts)), over `account:open-web`. It asks the backend for a single-use, 60-second handoff code (`POST /api/auth/handoff`) and opens `WEBSITE_BASE_URL/<locale>/app-sign-in?next=<page>#code=<code>`: the code rides in the **fragment**, which no server log or Referer sees, and the website trades it for a session of the browser's own. The session token itself never goes into a URL. Without a code (a backend that predates the endpoint, a network blip) the page opens anyway and the website asks the user to sign in, then continues to the same place. The locale prefix follows `uiLanguage`, since the website's locales are the app's. `test/web-account.test.mjs` pins the fragment, the paths, the plan-id check and the fallback.

Nothing needs to watch for the purchase coming back: the health-check ping refreshes the balance every 5 seconds while signed in. A password changed on the website signs out every other session, this one included, so the app returns to sign-in on the next ping - the same as any other device.

### Window and Stealth Mode

The main window reference is passed to `windowControlService` and `zoomService` after creation. Window bounds persist to Electron Store on `close` and are restored on next launch with minimum-size clamping (`MIN_WIDTH` / `MIN_HEIGHT` from [src/main/consts.ts](src/main/consts.ts)).
Expand Down
16 changes: 8 additions & 8 deletions src/main/api/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import {
AuthToken,
ChangePasswordRequest,
ForgotPasswordRequest,
HandoffCode,
LoginRequest,
ResetPasswordRequest,
SendVerificationCodeRequest,
Expand Down Expand Up @@ -38,6 +38,13 @@ export class AuthApi extends ApiClient {
return this.post('/api/auth/login', credentials);
}

/**
* A single-use code that signs the website in as this account (backend #89)
*/
async createHandoff(): Promise<ApiResponse<HandoffCode>> {
return this.post('/api/auth/handoff', {});
}

/**
* Logout current session
*/
Expand All @@ -52,13 +59,6 @@ export class AuthApi extends ApiClient {
return this.post('/api/auth/signup', data);
}

/**
* Change user password
*/
async changePassword(data: ChangePasswordRequest): Promise<ApiResponse<void>> {
return this.post<void>('/api/auth/change-password', data);
}

/**
* Request a password reset code.
*
Expand Down
39 changes: 2 additions & 37 deletions src/main/api/payment.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
/**
* Payment API
* Handles payment and credit operations
* The passes on sale. Checkout, status and history are the website's (see web-account.service.ts).
*/

import {
AvailableCurrency,
CreatePaymentRequest,
CreatePaymentResponse,
PaymentHistory,
PaymentPlan,
PaymentStatusResponse,
} from '../types/payment.js';
import { PaymentPlan } from '../types/payment.js';
import { ApiClient, ApiResponse } from './client.js';

export class PaymentApi extends ApiClient {
Expand All @@ -30,32 +23,4 @@ export class PaymentApi extends ApiClient {
> {
return this.get('/api/payment/subscription-plans');
}

/**
* Get available currencies for payment
*/
async getAvailableCurrencies(): Promise<ApiResponse<AvailableCurrency[]>> {
return this.get('/api/payment/currencies');
}

/**
* Create a new payment
*/
async createPayment(data: CreatePaymentRequest): Promise<ApiResponse<CreatePaymentResponse>> {
return this.post('/api/payment/create', data);
}

/**
* Get payment status
*/
async getPaymentStatus(paymentId: string): Promise<ApiResponse<PaymentStatusResponse>> {
return this.get(`/api/payment/status/${paymentId}`);
}

/**
* Get payment history
*/
async getPaymentHistory(): Promise<ApiResponse<PaymentHistory[]>> {
return this.get('/api/payment/history');
}
}
6 changes: 6 additions & 0 deletions src/main/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ export const BACKEND_BASE_URL = EnvUtil.isDev()
? 'http://localhost:8080'
: 'https://api.powerinterviewai.com';

// The website, whose account area is where billing, payment history and the password are managed.
// The app links there rather than keeping its own copy (see web-account.service.ts).
export const WEBSITE_BASE_URL = EnvUtil.isDev()
? 'http://localhost:3000'
: 'https://www.powerinterviewai.com';

// GitHub repo the release/publish workflow ships to. macOS reads releases from here directly
// (see mac-update.util.ts) since Squirrel.Mac's silent update needs real Developer ID signing,
// which this app does not have yet.
Expand Down
6 changes: 6 additions & 0 deletions src/main/ipc/account.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ipcMain } from 'electron';

import { accountService } from '../services/account.service.js';
import { WebAccountPage, webAccountService } from '../services/web-account.service.js';

export function registerAccountHandlers(): void {
// Push local account config changes (full name, profile, context) to the backend
Expand All @@ -27,4 +28,9 @@ export function registerAccountHandlers(): void {
ipcMain.handle('account:set-onboarding-completed', async (_event, completed: boolean) => {
return accountService.setOnboardingCompleted(completed);
});

// Billing, payment history and the password live on the website; this opens it signed in.
ipcMain.handle('account:open-web', async (_event, page: WebAccountPage, plan?: string) => {
return webAccountService.open(page, plan);
});
}
8 changes: 0 additions & 8 deletions src/main/ipc/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@ export function registerAuthHandlers(): void {
return authService.logout();
});

// Change password
ipcMain.handle(
'auth:change-password',
async (_event, currentPassword: string, newPassword: string) => {
return authService.changePassword(currentPassword, newPassword);
}
);

// Request a password reset code
ipcMain.handle('auth:forgot-password', async (_event, email: string) => {
return authService.forgotPassword(email);
Expand Down
55 changes: 1 addition & 54 deletions src/main/ipc/payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,7 @@
import { ipcMain } from 'electron';

import { paymentService } from '../services/payment.service.js';
import {
AvailableCurrency,
CreatePaymentRequest,
CreatePaymentResponse,
PaymentHistory,
PaymentStatusResponse,
SubscriptionPlanInfo,
} from '../types/payment.js';
import { SubscriptionPlanInfo } from '../types/payment.js';

export function registerPaymentHandlers(): void {
/**
Expand All @@ -25,50 +18,4 @@ export function registerPaymentHandlers(): void {
return paymentService.getPlans();
}
);

/**
* Get available payment currencies
*/
ipcMain.handle(
'payment:get-currencies',
async (): Promise<{ success: boolean; data?: AvailableCurrency[]; error?: string }> => {
return paymentService.getAvailableCurrencies();
}
);

/**
* Create a new payment
*/
ipcMain.handle(
'payment:create',
async (
_event,
data: CreatePaymentRequest
): Promise<{ success: boolean; data?: CreatePaymentResponse; error?: string }> => {
return paymentService.createPayment(data);
}
);

/**
* Get payment status
*/
ipcMain.handle(
'payment:get-status',
async (
_event,
paymentId: string
): Promise<{ success: boolean; data?: PaymentStatusResponse; error?: string }> => {
return paymentService.getPaymentStatus(paymentId);
}
);

/**
* Get payment history
*/
ipcMain.handle(
'payment:get-history',
async (): Promise<{ success: boolean; data?: PaymentHistory[]; error?: string }> => {
return paymentService.getPaymentHistory();
}
);
}
8 changes: 2 additions & 6 deletions src/main/preload.cts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ const electronApi = {
ipcRenderer.invoke('auth:signup', username, email, password, verificationCode),
login: (email: string, password: string) => ipcRenderer.invoke('auth:login', email, password),
logout: () => ipcRenderer.invoke('auth:logout'),
changePassword: (currentPassword: string, newPassword: string) =>
ipcRenderer.invoke('auth:change-password', currentPassword, newPassword),
forgotPassword: (email: string) => ipcRenderer.invoke('auth:forgot-password', email),
verifyPasswordResetCode: (email: string, code: string) =>
ipcRenderer.invoke('auth:verify-password-reset-code', email, code),
Expand All @@ -80,14 +78,12 @@ const electronApi = {
get: () => ipcRenderer.invoke('account:get'),
setOnboardingCompleted: (completed: boolean) =>
ipcRenderer.invoke('account:set-onboarding-completed', completed),
openWeb: (page: 'overview' | 'billing' | 'security', plan?: string) =>
ipcRenderer.invoke('account:open-web', page, plan),
},

payment: {
getPlans: () => ipcRenderer.invoke('payment:get-plans'),
getCurrencies: () => ipcRenderer.invoke('payment:get-currencies'),
create: (data: Record<string, unknown>) => ipcRenderer.invoke('payment:create', data),
getStatus: (paymentId: string) => ipcRenderer.invoke('payment:get-status', paymentId),
getHistory: () => ipcRenderer.invoke('payment:get-history'),
},

appState: {
Expand Down
46 changes: 2 additions & 44 deletions src/main/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { disableStealth } from './window-control.service.js';
* AuthService
* Wrapper around the low-level `AuthApi` client that provides
* higher-level methods used by the application (login, signup,
* logout, changePassword). Each method returns a simple result
* logout, password reset). Each method returns a simple result
* object with `success` and optional `error` message to keep
* caller-side handling straightforward.
*/
Expand Down Expand Up @@ -188,48 +188,6 @@ export class AuthService {
}
}

/**
* Change the authenticated user's password.
* The API expects `current_password` and `new_password` keys.
*/
async changePassword(
currentPassword: string,
newPassword: string
): Promise<{ success: boolean; error?: string }> {
try {
const response = await this.client.changePassword({
current_password: currentPassword,
new_password: newPassword,
});
if (response.error) {
return {
success: false,
error: response.error.message || uiStrings().authErrors.changePasswordFailed,
};
}

// Only persist when the user opted in - login/logout leave the store empty otherwise,
// and writing here would put credentials back behind their back.
//
// Guarded separately from the request, because by this line the password has already
// changed on the server. Letting a disk write decide the return value reports a failure
// for a change that happened, and the dialog then asks the user to try again with a
// current password that is no longer current, so the retry cannot work either. Same
// line `resetPassword` draws, and `login.tsx` before it.
try {
if (configStore.getConfig().rememberMe) {
configStore.updateConfig({ password: newPassword });
}
} catch (err) {
console.error('Failed to store the new password after change:', err);
}

return { success: true };
} catch {
return { success: false, error: uiStrings().authErrors.changePasswordFailed };
}
}

/**
* Request a password reset code for an address.
*
Expand Down Expand Up @@ -298,7 +256,7 @@ export class AuthService {
// The login form pre-fills from the store when rememberMe is on, and if what it holds
// is this account then the password in it is the one that just stopped working.
//
// Two guards, not one. `rememberMe` is the same check changePassword makes: login and
// Two guards, not one. `rememberMe` first: login and
// logout leave the store empty when the user did not opt in, and writing here would put
// credentials back on disk behind their back. The address check is specific to reset,
// which is the only password flow that runs while signed out and can therefore be run
Expand Down
Loading