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

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;
@@ -757,12 +758,15 @@ var FluxbaseAuth = class {
757
758
  * Send password reset email (Supabase-compatible)
758
759
  * Sends a password reset link to the provided email address
759
760
  * @param email - Email address to send reset link to
760
- * @param options - Optional configuration including CAPTCHA token
761
+ * @param options - Optional configuration including redirect URL and CAPTCHA token
761
762
  * @returns Promise with OTP-style response
762
763
  */
763
764
  async sendPasswordReset(email, options) {
764
765
  return wrapAsync(async () => {
765
766
  const requestBody = { email };
767
+ if (options?.redirectTo) {
768
+ requestBody.redirect_to = options.redirectTo;
769
+ }
766
770
  if (options?.captchaToken) {
767
771
  requestBody.captcha_token = options.captchaToken;
768
772
  }
@@ -778,6 +782,7 @@ var FluxbaseAuth = class {
778
782
  */
779
783
  async resetPasswordForEmail(email, options) {
780
784
  return this.sendPasswordReset(email, {
785
+ redirectTo: options?.redirectTo,
781
786
  captchaToken: options?.captchaToken
782
787
  });
783
788
  }
@@ -910,13 +915,22 @@ var FluxbaseAuth = class {
910
915
  * Exchange OAuth authorization code for session
911
916
  * This is typically called in your OAuth callback handler
912
917
  * @param code - Authorization code from OAuth callback
918
+ * @param state - State parameter from OAuth callback (for CSRF protection)
913
919
  */
914
- async exchangeCodeForSession(code) {
920
+ async exchangeCodeForSession(code, state) {
915
921
  return wrapAsync(async () => {
916
- const response = await this.fetch.post(
917
- "/api/v1/auth/oauth/callback",
918
- { code }
922
+ const provider = this.storage?.getItem(OAUTH_PROVIDER_KEY);
923
+ if (!provider) {
924
+ throw new Error("No OAuth provider found. Call signInWithOAuth first.");
925
+ }
926
+ const params = new URLSearchParams({ code });
927
+ if (state) {
928
+ params.append("state", state);
929
+ }
930
+ const response = await this.fetch.get(
931
+ `/api/v1/auth/oauth/${provider}/callback?${params.toString()}`
919
932
  );
933
+ this.storage?.removeItem(OAUTH_PROVIDER_KEY);
920
934
  const session = {
921
935
  ...response,
922
936
  expires_at: Date.now() + response.expires_in * 1e3
@@ -939,6 +953,7 @@ var FluxbaseAuth = class {
939
953
  }
940
954
  const url = result.data.url;
941
955
  if (typeof window !== "undefined") {
956
+ this.storage?.setItem(OAUTH_PROVIDER_KEY, provider);
942
957
  window.location.href = url;
943
958
  } else {
944
959
  throw new Error(