• Sets the reference to the setTokens function to avoid circular dependency

    Implements a dependency injection pattern to resolve circular dependencies between the token refresh and token operations modules. This function must be called during token system initialization before token refresh operations can be performed.

    Additionally, this function registers the scheduleTokenRefresh function with the token-operations module, creating a bidirectional relationship without direct cyclic imports.

    Parameters

    • setTokensFn: (tokens: AuthTokens) => void

      The function to use for storing tokens after refresh

    Returns void

    // During token system initialization
    import { setTokens } from "./token-operations";
    initTokenRefresh(setTokens);
    export function initTokenRefresh(
    setTokensFn: (tokens: AuthTokens) => void,
    ): void {
    setTokensFunction = setTokensFn;

    // Register the scheduleTokenRefresh function with token-operations if not already done
    if (!scheduleTokenRefreshFnRegistered) {
    scheduleTokenRefreshFnRegistered = true;
    import("./token-operations").then(({ setScheduleTokenRefreshFunction }) => {
    setScheduleTokenRefreshFunction(scheduleTokenRefresh);
    });
    }
    }