@insforge/react 1.0.2-refresh.1 → 1.0.2-refresh.3

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.d.cts CHANGED
@@ -29,6 +29,7 @@ interface InsforgeProviderProps {
29
29
  onAuthChange?: (user: InsforgeUser | null) => void;
30
30
  onSignIn?: (authToken: string) => Promise<void>;
31
31
  onSignOut?: () => Promise<void>;
32
+ onRefresh?: (authToken: string) => Promise<void>;
32
33
  /**
33
34
  * Initial auth state from server (for SSR hydration)
34
35
  * @internal - Not intended for public use, used by Next.js package
@@ -73,7 +74,7 @@ interface InsforgeProviderProps {
73
74
  * </InsforgeProvider>
74
75
  * ```
75
76
  */
76
- declare function InsforgeProviderCore({ children, baseUrl, afterSignInUrl, onAuthChange, onSignIn, onSignOut, initialState, }: InsforgeProviderProps): react_jsx_runtime.JSX.Element;
77
+ declare function InsforgeProviderCore({ children, baseUrl, afterSignInUrl, onAuthChange, onSignIn, onSignOut, onRefresh, initialState, }: InsforgeProviderProps): react_jsx_runtime.JSX.Element;
77
78
  declare function InsforgeProvider(props: InsforgeProviderProps): react_jsx_runtime.JSX.Element;
78
79
  /**
79
80
  * Hook to access Insforge context
package/dist/index.d.ts CHANGED
@@ -29,6 +29,7 @@ interface InsforgeProviderProps {
29
29
  onAuthChange?: (user: InsforgeUser | null) => void;
30
30
  onSignIn?: (authToken: string) => Promise<void>;
31
31
  onSignOut?: () => Promise<void>;
32
+ onRefresh?: (authToken: string) => Promise<void>;
32
33
  /**
33
34
  * Initial auth state from server (for SSR hydration)
34
35
  * @internal - Not intended for public use, used by Next.js package
@@ -73,7 +74,7 @@ interface InsforgeProviderProps {
73
74
  * </InsforgeProvider>
74
75
  * ```
75
76
  */
76
- declare function InsforgeProviderCore({ children, baseUrl, afterSignInUrl, onAuthChange, onSignIn, onSignOut, initialState, }: InsforgeProviderProps): react_jsx_runtime.JSX.Element;
77
+ declare function InsforgeProviderCore({ children, baseUrl, afterSignInUrl, onAuthChange, onSignIn, onSignOut, onRefresh, initialState, }: InsforgeProviderProps): react_jsx_runtime.JSX.Element;
77
78
  declare function InsforgeProvider(props: InsforgeProviderProps): react_jsx_runtime.JSX.Element;
78
79
  /**
79
80
  * Hook to access Insforge context
package/dist/index.js CHANGED
@@ -556,9 +556,18 @@ var InsforgeManager = class _InsforgeManager {
556
556
  this.notifyListeners();
557
557
  return { success: false, error: "no_session" };
558
558
  }
559
+ if (this.config.onRefresh && session.accessToken) {
560
+ try {
561
+ await this.config.onRefresh(session.accessToken);
562
+ } catch (error) {
563
+ if (error instanceof Error) {
564
+ console.error("[InsforgeManager] Error syncing token on refresh:", error.message);
565
+ }
566
+ }
567
+ }
559
568
  const userResult = await this.sdk.auth.getCurrentUser();
560
569
  if (userResult.data) {
561
- const profile = userResult.data.profile;
570
+ const profile = userResult.data.user.profile;
562
571
  const userData = {
563
572
  id: userResult.data.user.id,
564
573
  email: userResult.data.user.email,
@@ -600,7 +609,7 @@ var InsforgeManager = class _InsforgeManager {
600
609
  async handleAuthSuccess(authToken, fallbackUser) {
601
610
  const userResult = await this.sdk.auth.getCurrentUser();
602
611
  if (userResult.data) {
603
- const profile = userResult.data.profile;
612
+ const profile = userResult.data.user.profile;
604
613
  const userData = {
605
614
  id: userResult.data.user.id,
606
615
  email: userResult.data.user.email,
@@ -714,12 +723,12 @@ var InsforgeManager = class _InsforgeManager {
714
723
  if (result.data) {
715
724
  const userResult = await this.sdk.auth.getCurrentUser();
716
725
  if (userResult.data) {
717
- const profile = userResult.data.profile;
726
+ const profile = userResult.data.user.profile;
718
727
  const updatedUser = {
719
728
  id: userResult.data.user.id,
720
729
  email: userResult.data.user.email,
721
730
  name: profile?.name || "",
722
- avatarUrl: profile?.avatarUrl || ""
731
+ avatarUrl: profile?.avatar_url || ""
723
732
  };
724
733
  this.user = updatedUser;
725
734
  if (this.config.onAuthChange) {
@@ -2176,6 +2185,7 @@ function InsforgeProviderCore({
2176
2185
  onAuthChange,
2177
2186
  onSignIn,
2178
2187
  onSignOut,
2188
+ onRefresh,
2179
2189
  initialState
2180
2190
  }) {
2181
2191
  const manager = useMemo(
@@ -2184,9 +2194,10 @@ function InsforgeProviderCore({
2184
2194
  afterSignInUrl,
2185
2195
  onAuthChange,
2186
2196
  onSignIn,
2187
- onSignOut
2197
+ onSignOut,
2198
+ onRefresh
2188
2199
  }),
2189
- [baseUrl, afterSignInUrl, onAuthChange, onSignIn, onSignOut]
2200
+ [baseUrl, afterSignInUrl, onAuthChange, onSignIn, onSignOut, onRefresh]
2190
2201
  );
2191
2202
  if (initialState) {
2192
2203
  const currentState = manager.getState();
@@ -2199,7 +2210,19 @@ function InsforgeProviderCore({
2199
2210
  const unsubscribe = manager.subscribe((newState) => {
2200
2211
  setState(newState);
2201
2212
  });
2202
- void manager.initialize();
2213
+ void manager.initialize().then(() => {
2214
+ const params = new URLSearchParams(window.location.search);
2215
+ if (params.has("access_token")) {
2216
+ const url = new URL(window.location.href);
2217
+ url.searchParams.delete("access_token");
2218
+ url.searchParams.delete("user_id");
2219
+ url.searchParams.delete("email");
2220
+ url.searchParams.delete("name");
2221
+ url.searchParams.delete("csrf_token");
2222
+ url.searchParams.delete("error");
2223
+ window.history.replaceState({}, document.title, url.toString());
2224
+ }
2225
+ });
2203
2226
  return () => {
2204
2227
  unsubscribe();
2205
2228
  };