fix: hardcoded 14 günlük trial fallback'i app_settings.trial_days'e taşı

Profil bulunamadığında otomatik açılan trial süresi Postgres trigger'ıyla
(handle_new_user, 3 gün) tutarsızdı. İkisi de artık aynı app_settings
tablosundan okuyor (bkz. laawos/sql/19_configurable_trial_and_status_gate.sql).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Mustafa Yildiz
2026-08-18 12:43:01 +03:00
co-authored by Claude Sonnet 5
parent a5946eeb4a
commit fed881de49
+6 -2
View File
@@ -29,9 +29,13 @@ export const requireAuth = async (req: AuthenticatedRequest, res: Response, next
let userProfile = profile; let userProfile = profile;
if (!userProfile) { if (!userProfile) {
// Profil bulunamadıysa kullanıcıya otomatik deneme profili aç // Profil bulunamadıysa kullanıcıya otomatik deneme profili aç — süre
// app_settings.trial_days'ten okunuyor (bkz. sql/19_configurable_trial_and_status_gate.sql),
// handle_new_user() Postgres trigger'ıyla aynı kaynağı kullanıyor.
const { data: settings } = await supabase.from('app_settings').select('trial_days').maybeSingle();
const trialDays = settings?.trial_days ?? 7;
const trialEndDate = new Date(); const trialEndDate = new Date();
trialEndDate.setDate(trialEndDate.getDate() + 14); trialEndDate.setDate(trialEndDate.getDate() + trialDays);
const { data: newProfile } = await supabase const { data: newProfile } = await supabase
.from('profiles') .from('profiles')
.insert([{ id: user.id, license_status: 'trial', trial_end_date: trialEndDate.toISOString() }]) .insert([{ id: user.id, license_status: 'trial', trial_end_date: trialEndDate.toISOString() }])