* Exchange auth code for session tokens * Called after receiving code via deep link
(code: string)
| 43 | * Called after receiving code via deep link |
| 44 | */ |
| 45 | async exchangeCode(code: string): Promise<AuthData> { |
| 46 | const response = await fetch(`${this.getApiUrl()}/api/auth/desktop/exchange`, { |
| 47 | method: "POST", |
| 48 | headers: { "Content-Type": "application/json" }, |
| 49 | body: JSON.stringify({ |
| 50 | code, |
| 51 | deviceInfo: this.getDeviceInfo(), |
| 52 | }), |
| 53 | }) |
| 54 | |
| 55 | if (!response.ok) { |
| 56 | const error = await response.json().catch(() => ({ error: "Unknown error" })) |
| 57 | throw new Error(error.error || `Exchange failed: ${response.status}`) |
| 58 | } |
| 59 | |
| 60 | const data = await response.json() |
| 61 | |
| 62 | const authData: AuthData = { |
| 63 | token: data.token, |
| 64 | refreshToken: data.refreshToken, |
| 65 | expiresAt: data.expiresAt, |
| 66 | user: data.user, |
| 67 | } |
| 68 | |
| 69 | this.store.save(authData) |
| 70 | this.scheduleRefresh() |
| 71 | |
| 72 | return authData |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Get device info for session tracking |
no test coverage detected