import type { MiddlewareFunction, RouterContextProvider } from "react-router"; /** * Creates a context storage middleware that stores the context, and request, * in an AsyncLocalStorage. * * This is useful for accessing the context in any part of the application * inside loaders or actions, but without needing to pass the context around * from loaders or actions to those functions. * * After the middleware is added, any function that needs the context can * call the `getContext` function to retrieve the context from the storage. * * @returns The context storage middleware and a function to get the context from the storage * @example * // app/middlewares/context-storage.ts * import { createContextStorageMiddleware } from "remix-utils"; * * export const [contextStorageMiddleware, getContext, getRequest] = createContextStorageMiddleware(); * * // app/root.tsx * import { contextStorageMiddleware } from "~/middlewares/context-storage"; * export const middleware: Route.MiddlewareFunction[] = [contextStorageMiddleware]; * * // app/helpers/authenticate.ts * import { getContext } from "~/middlewares/context-storage"; * import { getSession } from "~/middlewares/session"; * * export function authenticate() { * let context = getContext(); * let session = getSession(context); * // code to authenticate the user * } */ export declare function createContextStorageMiddleware(): createContextStorageMiddleware.ReturnType; export declare namespace createContextStorageMiddleware { type ReturnType = [ MiddlewareFunction, () => Readonly, () => Request ]; }