Fijar trial a 14 días en alta de tenant y reforzar filtro por tenant en escrituras
This commit is contained in:
@@ -1,16 +1,11 @@
|
||||
'use server';
|
||||
|
||||
import { redirect } from 'next/navigation';
|
||||
import { eq } from 'drizzle-orm';
|
||||
import { db } from '@/db';
|
||||
import { tenants } from '@/db/schema';
|
||||
import { signupSchema, slugify } from '@/lib/validation/signup';
|
||||
import { getUserByEmail, createTenantWithOwner, slugDisponible } from '@/db/auth-queries';
|
||||
import { hashPassword } from '@/lib/auth/password';
|
||||
import { createSession } from '@/lib/auth/session';
|
||||
|
||||
const TRIAL_MS = 14 * 24 * 60 * 60 * 1000;
|
||||
|
||||
export async function signup(_prev: string | null, formData: FormData): Promise<string | null> {
|
||||
const parsed = signupSchema.safeParse(Object.fromEntries(formData));
|
||||
if (!parsed.success) return parsed.error.issues[0]?.message ?? 'Datos no válidos.';
|
||||
@@ -23,7 +18,7 @@ export async function signup(_prev: string | null, formData: FormData): Promise<
|
||||
while (!(await slugDisponible(slug))) slug = `${slugify(data.empresa)}-${++n}`;
|
||||
|
||||
const passwordHash = await hashPassword(data.password);
|
||||
const { tenant, user } = await createTenantWithOwner({
|
||||
const { user } = await createTenantWithOwner({
|
||||
nombreEmpresa: data.empresa,
|
||||
slug,
|
||||
provincia: data.provincia,
|
||||
@@ -32,11 +27,6 @@ export async function signup(_prev: string | null, formData: FormData): Promise<
|
||||
nombre: data.nombre,
|
||||
});
|
||||
|
||||
await db
|
||||
.update(tenants)
|
||||
.set({ trialEndsAt: new Date(Date.now() + TRIAL_MS) })
|
||||
.where(eq(tenants.id, tenant.id));
|
||||
|
||||
await createSession(user.id);
|
||||
redirect('/panel');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user