@timpel/forumkit-sdk-react-native 0.2.4 → 0.2.5

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.ts CHANGED
@@ -16,6 +16,7 @@ type ThemeTokens = {
16
16
  type ForumKitConfig = {
17
17
  forumId: string;
18
18
  token: string;
19
+ getToken?: () => Promise<string>;
19
20
  theme?: ThemeTokens;
20
21
  apiUrl?: string;
21
22
  onLogout?: () => void;
package/dist/index.js CHANGED
@@ -833,11 +833,12 @@ function SessionProvider({ config, children }) {
833
833
  if (cancelled) return;
834
834
  expiresAtRef.current = Date.now() + expiresIn * 1e3;
835
835
  refreshTimer = setTimeout(() => {
836
- void refresh();
836
+ void refresh(true);
837
837
  }, expiresIn * 1e3 * 0.8);
838
838
  }
839
- function refresh() {
840
- return createSession(apiUrl, config.token).then((result) => {
839
+ function refresh(isRenewal = false) {
840
+ const tokenPromise = isRenewal && config.getToken ? config.getToken() : Promise.resolve(config.token);
841
+ return tokenPromise.then((hostToken) => createSession(apiUrl, hostToken)).then((result) => {
841
842
  if (cancelled) return;
842
843
  setState({ status: "ready", forumId: config.forumId, apiUrl, sessionToken: result.sessionToken, userId: result.userId, role: result.role, error: null });
843
844
  scheduleRefresh(result.expiresIn);
@@ -846,7 +847,7 @@ function SessionProvider({ config, children }) {
846
847
  const message = err instanceof Error ? err.message : "Failed to create session";
847
848
  setState({ status: "error", forumId: config.forumId, apiUrl, sessionToken: null, userId: null, role: null, error: message });
848
849
  retryTimer = setTimeout(() => {
849
- void refresh();
850
+ void refresh(true);
850
851
  }, RETRY_DELAY_MS);
851
852
  });
852
853
  }
@@ -855,10 +856,10 @@ function SessionProvider({ config, children }) {
855
856
  const msRemaining = expiresAtRef.current - Date.now();
856
857
  if (refreshTimer) clearTimeout(refreshTimer);
857
858
  if (msRemaining <= 0) {
858
- void refresh();
859
+ void refresh(true);
859
860
  } else {
860
861
  refreshTimer = setTimeout(() => {
861
- void refresh();
862
+ void refresh(true);
862
863
  }, msRemaining * 0.8);
863
864
  }
864
865
  });