UNPKG

membros-react-sdk

Version:

React authentication library for Membros platform with subscription management and plan-based access control

81 lines 2.64 kB
"use strict"; // Cookie utilities to replace nookies dependency // Provides the same interface as nookies for seamless replacement Object.defineProperty(exports, "__esModule", { value: true }); exports.destroyCookie = exports.parseCookies = exports.setCookie = void 0; /** * Set a cookie with the given name, value and options */ const setCookie = (ctx, // For compatibility with nookies API (not used in client-side) name, value, options = {}) => { if (typeof window === 'undefined') { // Server-side handling would go here if needed return; } let cookieString = `${encodeURIComponent(name)}=${encodeURIComponent(value)}`; if (options.path) { cookieString += `; path=${options.path}`; } if (options.domain) { cookieString += `; domain=${options.domain}`; } if (options.maxAge) { cookieString += `; max-age=${options.maxAge}`; } if (options.expires) { cookieString += `; expires=${options.expires.toUTCString()}`; } if (options.secure) { cookieString += `; secure`; } if (options.sameSite) { cookieString += `; samesite=${options.sameSite}`; } if (options.httpOnly) { cookieString += `; httponly`; } document.cookie = cookieString; }; exports.setCookie = setCookie; /** * Parse cookies from document.cookie and return as an object */ const parseCookies = (ctx) => { if (typeof window === 'undefined') { // Server-side handling would go here if needed return {}; } const cookies = {}; if (document.cookie) { document.cookie.split(';').forEach(cookie => { const [name, value] = cookie.trim().split('='); if (name && value) { try { cookies[decodeURIComponent(name)] = decodeURIComponent(value); } catch (e) { // Skip malformed cookies console.warn('Failed to parse cookie:', name, value); } } }); } return cookies; }; exports.parseCookies = parseCookies; /** * Remove a cookie by setting its expiration to the past */ const destroyCookie = (ctx, // For compatibility with nookies API (not used in client-side) name, options = {}) => { if (typeof window === 'undefined') { // Server-side handling would go here if needed return; } (0, exports.setCookie)(ctx, name, '', { ...options, expires: new Date(0), // Set expiration to Unix epoch (past date) }); }; exports.destroyCookie = destroyCookie; //# sourceMappingURL=cookies.js.map