@bunbase-ae/js 2.4.1-next.161.79fd318 → 2.4.1-next.162.9c38140

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/auth.ts +35 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bunbase-ae/js",
3
- "version": "2.4.1-next.161.79fd318",
3
+ "version": "2.4.1-next.162.9c38140",
4
4
  "type": "module",
5
5
  "description": "TypeScript/JavaScript SDK for BunBase",
6
6
  "license": "UNLICENSED",
package/src/auth.ts CHANGED
@@ -181,6 +181,41 @@ export class AuthClient {
181
181
  return result;
182
182
  }
183
183
 
184
+ // Redeem an OAuth handoff code for the token pair.
185
+ //
186
+ // The OAuth callback redirects to `{APP_URL}/auth/callback?handoff=<code>`.
187
+ // Tokens no longer travel through the URL query string (which would leak
188
+ // them into browser history, proxy logs, and third-party Referer headers);
189
+ // instead, the frontend reads the `handoff` param and posts it here.
190
+ //
191
+ // Single-use — a second call with the same code returns 404.
192
+ async exchangeHandoff(code: string): Promise<{
193
+ access_token: string;
194
+ refresh_token: string;
195
+ expires_in: number;
196
+ }> {
197
+ const result = await this.http.request<{
198
+ access_token: string;
199
+ refresh_token: string;
200
+ expires_in: number;
201
+ }>("POST", "/api/v1/auth/oauth/handoff", {
202
+ body: { handoff: code },
203
+ skipAuth: true,
204
+ });
205
+ this.http.setTokens(result.access_token, result.refresh_token);
206
+ // Populate the reactive snapshot so useAuth() lights up without the caller
207
+ // having to issue a separate me() round-trip. Swallow errors here — the
208
+ // token store is already primed; any auth-dependent view can retry.
209
+ try {
210
+ const user = await this.me();
211
+ this.cachedUser = user;
212
+ this.patchSnapshot({ user });
213
+ } catch {
214
+ // Caller can retry via auth.me() — tokens are already stored.
215
+ }
216
+ return result;
217
+ }
218
+
184
219
  async refresh(): Promise<AuthResult> {
185
220
  const refreshToken = this.http.getRefreshToken();
186
221
  if (!refreshToken) throw new Error("No refresh token stored. Call login() first.");