assembly/composables/useCookies.ts

26 lines
466 B
TypeScript
Raw Normal View History

2021-09-06 22:36:09 +00:00
import { useContext } from "@nuxtjs/composition-api";
import Cookies from "universal-cookie";
export function useCookies() {
const { ssrContext } = useContext();
const cookies = new Cookies(
ssrContext ? ssrContext.req.headers.cookie : null
);
function get(key: string) {
return cookies.get(key);
}
function set(key: string, value: any) {
return cookies.set(key, value, {
path: "/"
});
}
return {
get,
set
};
}