Spaces:
Sleeping
Sleeping
Download utils/authCookies.js from Mahmoud7456/MultiUsersSalesSystem: direct link, hf CLI and curl.
- Browser
- Download file 2.14 kB
-
https://huggingface.co/spaces/Mahmoud7456/MultiUsersSalesSystem/resolve/main/utils/authCookies.js
- Command line
-
hf download hf://spaces/Mahmoud7456/MultiUsersSalesSystem/utils/authCookies.js
-
curl -L -o authCookies.js https://huggingface.co/spaces/Mahmoud7456/MultiUsersSalesSystem/resolve/main/utils/authCookies.js
2.14 kB
| import crypto from "crypto"; | |
| export const AUTH_COOKIE_NAME = "sales_system_session"; | |
| const SEVEN_DAYS_IN_MS = 7 * 24 * 60 * 60 * 1000; | |
| export const createSessionToken = () => ({ | |
| token: crypto.randomBytes(32).toString("hex"), | |
| expiresAt: new Date(Date.now() + SEVEN_DAYS_IN_MS), | |
| }); | |
| export const getAuthCookieOptions = () => ({ | |
| httpOnly: true, | |
| sameSite: "none", | |
| secure: process.env.NODE_ENV === "production", | |
| maxAge: SEVEN_DAYS_IN_MS, | |
| path: "/", | |
| }); | |
| export const getClearCookieOptions = () => ({ | |
| httpOnly: true, | |
| sameSite: "none", | |
| secure: process.env.NODE_ENV === "production", | |
| path: "/", | |
| }); | |
| export const setAuthCookie = (res, token) => { | |
| res.cookie(AUTH_COOKIE_NAME, token, getAuthCookieOptions()); | |
| }; | |
| export const clearAuthCookie = (res) => { | |
| res.clearCookie(AUTH_COOKIE_NAME, getClearCookieOptions()); | |
| }; | |
| export const parseCookies = (cookieHeader = "") => | |
| cookieHeader.split(";").reduce((cookies, rawCookie) => { | |
| const [name, ...valueParts] = rawCookie.trim().split("="); | |
| if (!name) { | |
| return cookies; | |
| } | |
| cookies[name] = decodeURIComponent(valueParts.join("=")); | |
| return cookies; | |
| }, {}); | |
| export const toSlug = (value = "") => | |
| value | |
| .toString() | |
| .trim() | |
| .toLowerCase() | |
| .replace(/[^a-z0-9]+/g, "-") | |
| .replace(/^-+|-+$/g, "") | |
| .replace(/-{2,}/g, "-"); | |
| export const buildTenantCredentialsWhatsApp = ({ | |
| ownerName, | |
| username, | |
| temporaryPassword, | |
| loginUrl, | |
| }) => { | |
| const message = [ | |
| `مرحباً ${ownerName || "صاحب النشاط"}`, | |
| `تم إنشاء حساب نشاطك التجاري على منصة دفترى.`, | |
| `اسم المستخدم: ${username}`, | |
| `كلمة المرور المؤقتة: ${temporaryPassword}`, | |
| `رابط الدخول: ${loginUrl}`, | |
| "يرجى تسجيل الدخول وتغيير كلمة المرور بعد أول استخدام.", | |
| ].join("\n"); | |
| return { | |
| message, | |
| whatsappLink: `https://wa.me/?text=${encodeURIComponent(message)}`, | |
| }; | |
| }; | |