Fijar trial a 14 días en alta de tenant y reforzar filtro por tenant en escrituras

This commit is contained in:
Carlos Narro
2026-05-30 20:02:02 +02:00
parent 4f48b1591c
commit b84b2f37a2
3 changed files with 9 additions and 15 deletions

View File

@@ -1,7 +1,8 @@
import { eq } from 'drizzle-orm';
import { db } from './index';
import { users, tenants } from './schema';
import { sessionExpiry } from '@/lib/auth/tokens';
const TRIAL_MS = 14 * 24 * 60 * 60 * 1000;
export async function getUserByEmail(email: string) {
const [row] = await db.select().from(users).where(eq(users.email, email)).limit(1);
@@ -28,7 +29,7 @@ export async function createTenantWithOwner(input: {
nombreEmpresa: input.nombreEmpresa,
provincia: input.provincia,
subscriptionStatus: 'trial',
trialEndsAt: sessionExpiry(new Date()),
trialEndsAt: new Date(Date.now() + TRIAL_MS),
})
.returning();