* Update user profile on server and locally
(updates: { name?: string })
| 226 | * Update user profile on server and locally |
| 227 | */ |
| 228 | async updateUser(updates: { name?: string }): Promise<AuthUser | null> { |
| 229 | const token = await this.getValidToken() |
| 230 | if (!token) { |
| 231 | throw new Error("Not authenticated") |
| 232 | } |
| 233 | |
| 234 | // Update on server using X-Desktop-Token header |
| 235 | const response = await fetch(`${this.getApiUrl()}/api/user/profile`, { |
| 236 | method: "PATCH", |
| 237 | headers: { |
| 238 | "Content-Type": "application/json", |
| 239 | "X-Desktop-Token": token, |
| 240 | }, |
| 241 | body: JSON.stringify({ |
| 242 | display_name: updates.name, |
| 243 | }), |
| 244 | }) |
| 245 | |
| 246 | if (!response.ok) { |
| 247 | const error = await response.json().catch(() => ({ error: "Unknown error" })) |
| 248 | throw new Error(error.error || `Update failed: ${response.status}`) |
| 249 | } |
| 250 | |
| 251 | // Update locally |
| 252 | return this.store.updateUser({ name: updates.name ?? null }) |
| 253 | } |
| 254 | |
| 255 | /** |
| 256 | * Fetch user's subscription plan from web backend |
nothing calls this directly
no test coverage detected