Add domain filter to cookie template function

This commit is contained in:
Gregory Schier
2026-05-06 11:09:43 -07:00
parent 41fe01adb9
commit 5978cec71e
9 changed files with 179 additions and 15 deletions

View File

@@ -12,11 +12,22 @@ export const plugin: PluginDefinition = {
name: "name",
label: "Cookie Name",
},
{
type: "text",
name: "domain",
label: "Domain",
optional: true,
},
],
async onRender(ctx: Context, args: CallTemplateFunctionArgs): Promise<string | null> {
// The legacy name was cookie_name, but we changed it
const name = args.values.cookie_name ?? args.values.name;
return ctx.cookies.getValue({ name: String(name) });
const domain = String(args.values.domain ?? "").trim();
return ctx.cookies.getValue({
name: String(name),
...(domain.length > 0 ? { domain } : {}),
});
},
},
],