Initial commit: SmoothSchedule multi-tenant scheduling platform
This commit includes: - Django backend with multi-tenancy (django-tenants) - React + TypeScript frontend with Vite - Platform administration API with role-based access control - Authentication system with token-based auth - Quick login dev tools for testing different user roles - CORS and CSRF configuration for local development - Docker development environment setup 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
46
frontend/src/utils/cookies.ts
Normal file
46
frontend/src/utils/cookies.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* Cookie utilities for cross-subdomain token storage
|
||||
*/
|
||||
|
||||
/**
|
||||
* Set a cookie with domain attribute for cross-subdomain access
|
||||
* Uses .lvh.me for local development (lvh.me supports subdomains, unlike localhost)
|
||||
*/
|
||||
export const setCookie = (name: string, value: string, days: number = 7) => {
|
||||
const expires = new Date();
|
||||
expires.setTime(expires.getTime() + days * 24 * 60 * 60 * 1000);
|
||||
|
||||
// Set cookie with domain=.lvh.me for local dev, accessible across all subdomains
|
||||
// For localhost, don't set domain attribute - let it default to current host
|
||||
const hostname = window.location.hostname;
|
||||
const isLocalhost = hostname === 'localhost' || hostname === '127.0.0.1';
|
||||
const domainAttr = hostname.includes('lvh.me') ? `;domain=.lvh.me` : isLocalhost ? '' : `;domain=${hostname}`;
|
||||
|
||||
document.cookie = `${name}=${value};expires=${expires.toUTCString()}${domainAttr};path=/;SameSite=Lax`;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get a cookie value by name
|
||||
*/
|
||||
export const getCookie = (name: string): string | null => {
|
||||
const nameEQ = name + '=';
|
||||
const ca = document.cookie.split(';');
|
||||
|
||||
for (let i = 0; i < ca.length; i++) {
|
||||
let c = ca[i];
|
||||
while (c.charAt(0) === ' ') c = c.substring(1, c.length);
|
||||
if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Delete a cookie
|
||||
*/
|
||||
export const deleteCookie = (name: string) => {
|
||||
const hostname = window.location.hostname;
|
||||
const isLocalhost = hostname === 'localhost' || hostname === '127.0.0.1';
|
||||
const domainAttr = hostname.includes('lvh.me') ? `;domain=.lvh.me` : isLocalhost ? '' : `;domain=${hostname}`;
|
||||
document.cookie = `${name}=;expires=Thu, 01 Jan 1970 00:00:00 UTC${domainAttr};path=/;`;
|
||||
};
|
||||
Reference in New Issue
Block a user