(auth: { initData: string } | { accessToken: string })
| 151 | } |
| 152 | |
| 153 | async authenticate(auth: { initData: string } | { accessToken: string }): Promise<AuthResponse> { |
| 154 | const res = await fetch(this.buildUrl('/api/auth'), { |
| 155 | method: 'POST', |
| 156 | headers: { 'content-type': 'application/json' }, |
| 157 | body: JSON.stringify(auth) |
| 158 | }) |
| 159 | |
| 160 | if (!res.ok) { |
| 161 | const body = await res.text().catch(() => '') |
| 162 | const code = parseErrorCode(body) |
| 163 | const detail = body ? `: ${body}` : '' |
| 164 | throw new ApiError(`Auth failed: HTTP ${res.status} ${res.statusText}${detail}`, res.status, code, body || undefined) |
| 165 | } |
| 166 | |
| 167 | return await res.json() as AuthResponse |
| 168 | } |
| 169 | |
| 170 | async bind(auth: { initData: string; accessToken: string }): Promise<AuthResponse> { |
| 171 | const res = await fetch(this.buildUrl('/api/bind'), { |
no test coverage detected