You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@svuick/cookie

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

@svuick/cookie

0.0.8
unpublished
latest
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

@svuick/cookie

npm (scoped)

Install

Install with npm

npm i @svuick/cookie

Install with pnpm

pnpm i @svuick/cookie

Install with yarn

yarn add @svuick/cookie

Setup

src/hooks.ts

import { register } from '@svuick/core/hooks';
import cookie from '@svuick/cookie/hooks';

register(cookie);

export { handle } from '@svuick/core/hooks';

The plugin provides a cookie object in the request locals.

src/routes/api/endpoint.ts

export const get: Svuick.RequestHandler = (request) => {
	console.log(request.locals.cookie);
	return {
        body: request.locals.cookie["key"] // or ...cookie.key
		status: 200
	};
};

Documentation

setCookie

src/routes/api/endpoint.ts

import { setCookie } from '@svuick/cookie';

export const post: Svuick.RequestHandler = () => {
	const { headers } = setCookie('key', 'value', {
		maxAge: 12345
        secure: false,
        sameSite: 'lax',
        httpOnly: true
	});

	return { headers };
};

src/hooks.ts

import { setCookie } from '@svuick/cookie';

export const handle: Suick.Handle = async ({ request, resolve }) => {
    const response = await resolve(request);
	return setCookie(response, 'key', 'value', {
		maxAge: 12345
        secure: false,
        sameSite: 'lax',
        httpOnly: true
	});
};

clearCookie

src/routes/api/endpoint.ts

import { clearCookie } from '@svuick/cookie';

export const post: Svuick.RequestHandler = () => {
	const { headers } = clearCookie('key', {
		maxAge: 12345
        secure: false,
        sameSite: 'lax',
        httpOnly: true
	});

	return { headers };
};

src/hooks.ts

import { clearCookie } from '@svuick/cookie';

export const handle: Suick.Handle = async ({ request, resolve }) => {
    const response = await resolve(request);
	return clearCookie(response, 'key', {
		maxAge: 12345
        secure: false,
        sameSite: 'lax',
        httpOnly: true
	});
};

encryptCookie

src/routes/api/endpoint.ts

import { encryptCookie, setCookie } from '@svuick/cookie';

export const post: Svuick.RequestHandler = (request) => {
	const cookieValue = 'secret-data';
	const secureValue = encryptCookie(cookieValue, { key: 'long-and-secure-key' });
	const { headers } = setCookie('key', secureValue);
	return {
		headers,
		status: 204
	};
};

decryptCookie

src/routes/api/endpoint.ts

import { decryptCookie } from '@svuick/cookie';

export const get: Svuick.RequestHandler = (request) => {
	const cookieValue = request.locals.cookie['key'];
	const value = decryptCookie(cookieValue, { key: 'long-and-secure-key' });
	return {
		body: value,
		status: 200
	};
};

Licence

Licensed under MIT.

Keywords

svelte

FAQs

Package last updated on 03 Feb 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts