Skip to content

Instantly share code, notes, and snippets.

@coolhome
Created July 3, 2018 02:53
Show Gist options
  • Save coolhome/0d16db16f07f03c51c69ce7341f64dea to your computer and use it in GitHub Desktop.
Save coolhome/0d16db16f07f03c51c69ce7341f64dea to your computer and use it in GitHub Desktop.
const { jarFromCookies } = require('insomnia-cookies');
module.exports.templateTags = [
{
name: 'cookieJar',
displayName: 'CookieJar',
description: 'reference cookie value from cookie jar',
args: [
{
type: 'string',
displayName: "Cookie Domain"
},
{
type: 'string',
displayName: "Cookie Key"
}
],
async run(context, cookieDomain, cookieName) {
const { meta } = context;
if (!meta.requestId || !meta.workspaceId) {
return null;
}
const workspace = await context.util.models.workspace.getById(
meta.workspaceId
);
if (!workspace) {
throw new Error(`Workspace not found for ${meta.workspaceId}`);
}
const cookieJar = await context.util.models.cookieJar.getOrCreateForWorkspace(
workspace
);
const cookie = cookieJar.cookies.find(cookie => cookie.domain == cookieDomain && cookie.key == cookieName);
return cookie ? cookie.value : null;
}
}
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment