@mastra/core
Version:
25 lines (24 loc) • 968 B
JavaScript
import { a as MASTRA_NORMALIZED_USER_KEY } from "./request-context-COnZHt2-.js";
// src/utils/dynamic-argument.ts
/**
* Read the authenticated end user from the request context.
*
* The server auth middleware stores the normalized user under
* `MASTRA_NORMALIZED_USER_KEY` after an auth provider authenticates the
* request. Returns `undefined` when the request is unauthenticated, no auth
* provider is configured, or the stored value is malformed.
*/
function getRequestUser(requestContext) {
const user = requestContext?.getRaw(MASTRA_NORMALIZED_USER_KEY);
if (user && typeof user === "object" && typeof user.id === "string") return user;
}
function resolveDynamicArgument(value, { requestContext, mastra }) {
if (typeof value !== "function") return value;
return value({
requestContext,
mastra,
user: getRequestUser(requestContext)
});
}
export { resolveDynamicArgument as n, getRequestUser as t };
//# sourceMappingURL=dynamic-argument-BzPK3qPN.js.map