@fluxbase/sdk 0.0.1-rc.115 → 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(
@@ -948,6 +961,59 @@ var FluxbaseAuth = class {
948
961
  return { provider, url };
949
962
  });
950
963
  }
964
+ /**
965
+ * Get OAuth logout URL for a provider
966
+ * Use this to get the logout URL without automatically redirecting
967
+ * @param provider - OAuth provider name (e.g., 'google', 'github')
968
+ * @param options - Optional logout configuration
969
+ * @returns Promise with OAuth logout response including redirect URL if applicable
970
+ *
971
+ * @example
972
+ * ```typescript
973
+ * const { data, error } = await client.auth.getOAuthLogoutUrl('google')
974
+ * if (!error && data.redirect_url) {
975
+ * // Redirect user to complete logout at provider
976
+ * window.location.href = data.redirect_url
977
+ * }
978
+ * ```
979
+ */
980
+ async getOAuthLogoutUrl(provider, options) {
981
+ return wrapAsync(async () => {
982
+ const response = await this.fetch.post(
983
+ `/api/v1/auth/oauth/${provider}/logout`,
984
+ options || {}
985
+ );
986
+ this.clearSession();
987
+ return response;
988
+ });
989
+ }
990
+ /**
991
+ * Sign out with OAuth provider logout
992
+ * Revokes tokens at the OAuth provider and optionally redirects for OIDC logout
993
+ * @param provider - OAuth provider name (e.g., 'google', 'github')
994
+ * @param options - Optional logout configuration
995
+ * @returns Promise with OAuth logout response
996
+ *
997
+ * @example
998
+ * ```typescript
999
+ * // This will revoke tokens and redirect to provider's logout page if supported
1000
+ * await client.auth.signOutWithOAuth('google', {
1001
+ * redirect_url: 'https://myapp.com/logged-out'
1002
+ * })
1003
+ * ```
1004
+ */
1005
+ async signOutWithOAuth(provider, options) {
1006
+ return wrapAsync(async () => {
1007
+ const result = await this.getOAuthLogoutUrl(provider, options);
1008
+ if (result.error) {
1009
+ throw result.error;
1010
+ }
1011
+ if (result.data.requires_redirect && result.data.redirect_url && typeof window !== "undefined") {
1012
+ window.location.href = result.data.redirect_url;
1013
+ }
1014
+ return result.data;
1015
+ });
1016
+ }
951
1017
  /**
952
1018
  * Sign in with OTP (One-Time Password) - Supabase-compatible
953
1019
  * Sends a one-time password via email or SMS for passwordless authentication