@sanity/sdk 2.11.0 → 2.11.1

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.
@@ -1,5 +1,5 @@
1
1
  import { createClient, CorsOriginError } from "@sanity/client";
2
- import { Observable, map, distinctUntilChanged, shareReplay, skip, defer, finalize, filter, exhaustMap, timer, switchMap, takeWhile, from, firstValueFrom, EMPTY, fromEvent, catchError, NEVER, first, race, startWith, pairwise, mergeMap, groupBy, of, combineLatest, tap, share } from "rxjs";
2
+ import { Observable, map, distinctUntilChanged, shareReplay, skip, defer, finalize, filter, exhaustMap, timer, switchMap, takeWhile, from, firstValueFrom, catchError, EMPTY, fromEvent, NEVER, first, race, startWith, pairwise, mergeMap, groupBy, of, combineLatest, tap, share } from "rxjs";
3
3
  import { createSelector } from "reselect";
4
4
  import { createImageUrlBuilder } from "@sanity/image-url";
5
5
  import { devtools } from "zustand/middleware";
@@ -547,16 +547,21 @@ const refreshStampedToken = ({ state }) => {
547
547
  uri: "/users/me",
548
548
  method: "GET",
549
549
  tag: "users.get-current"
550
- })
550
+ }).pipe(
551
+ /**
552
+ * Catch inside switchMap so the outer subscription survives.
553
+ * Without this, a 401 terminates the subscription permanently
554
+ * and subsequent token refreshes via comlink never re-fetch /users/me.
555
+ * @see SDK-1409
556
+ */
557
+ catchError((error) => (state.set("setError", { authState: { type: AuthStateType.ERROR, error } }), EMPTY))
558
+ )
551
559
  )
552
560
  ).subscribe({
553
561
  next: (currentUser) => {
554
562
  state.set("setCurrentUser", (prev) => ({
555
563
  authState: prev.authState.type === AuthStateType.LOGGED_IN ? { ...prev.authState, currentUser } : prev.authState
556
564
  }));
557
- },
558
- error: (error) => {
559
- state.set("setError", { authState: { type: AuthStateType.ERROR, error } });
560
565
  }
561
566
  });
562
567
  };