@fluxbase/sdk 0.0.1-rc.116 → 0.0.1-rc.117

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.
package/dist/index.cjs CHANGED
@@ -333,6 +333,7 @@ async function wrapAsyncVoid(operation) {
333
333
 
334
334
  // src/auth.ts
335
335
  var AUTH_STORAGE_KEY = "fluxbase.auth.session";
336
+ var OAUTH_PROVIDER_KEY = "fluxbase.auth.oauth_provider";
336
337
  var AUTO_REFRESH_TICK_THRESHOLD = 10;
337
338
  var AUTO_REFRESH_TICK_MINIMUM = 1e3;
338
339
  var MAX_REFRESH_RETRIES = 3;
@@ -910,13 +911,24 @@ var FluxbaseAuth = class {
910
911
  * Exchange OAuth authorization code for session
911
912
  * This is typically called in your OAuth callback handler
912
913
  * @param code - Authorization code from OAuth callback
914
+ * @param state - State parameter from OAuth callback (for CSRF protection)
913
915
  */
914
- async exchangeCodeForSession(code) {
916
+ async exchangeCodeForSession(code, state) {
915
917
  return wrapAsync(async () => {
916
- const response = await this.fetch.post(
917
- "/api/v1/auth/oauth/callback",
918
- { code }
918
+ const provider = this.storage?.getItem(OAUTH_PROVIDER_KEY);
919
+ if (!provider) {
920
+ throw new Error(
921
+ "No OAuth provider found. Call signInWithOAuth first."
922
+ );
923
+ }
924
+ const params = new URLSearchParams({ code });
925
+ if (state) {
926
+ params.append("state", state);
927
+ }
928
+ const response = await this.fetch.get(
929
+ `/api/v1/auth/oauth/${provider}/callback?${params.toString()}`
919
930
  );
931
+ this.storage?.removeItem(OAUTH_PROVIDER_KEY);
920
932
  const session = {
921
933
  ...response,
922
934
  expires_at: Date.now() + response.expires_in * 1e3
@@ -939,6 +951,7 @@ var FluxbaseAuth = class {
939
951
  }
940
952
  const url = result.data.url;
941
953
  if (typeof window !== "undefined") {
954
+ this.storage?.setItem(OAUTH_PROVIDER_KEY, provider);
942
955
  window.location.href = url;
943
956
  } else {
944
957
  throw new Error(