feat: dashboard Second Brain, essai 7 jours et vérification e-mail
Rendre le dashboard actionnable (inbox, peek, carte mentale), aligner la facturation sur l’essai 7 jours, et bloquer le login e-mail tant que l’adresse n’est pas confirmée. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
34
memento-note/lib/billing/trial.ts
Normal file
34
memento-note/lib/billing/trial.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { prisma } from '@/lib/prisma'
|
||||
|
||||
export { SUBSCRIPTION_TRIAL_DAYS } from '@/lib/billing/trial-constants'
|
||||
|
||||
/**
|
||||
* Offer a trial only to users who never held a real Stripe subscription.
|
||||
* Users with cus_mock / price_mock leftovers from local tests are still eligible
|
||||
* if they never had a non-mock stripeSubscriptionId.
|
||||
*/
|
||||
export async function shouldOfferSubscriptionTrial(userId: string): Promise<boolean> {
|
||||
const sub = await prisma.subscription.findUnique({
|
||||
where: { userId },
|
||||
select: {
|
||||
stripeSubscriptionId: true,
|
||||
tier: true,
|
||||
status: true,
|
||||
trialEndsAt: true,
|
||||
},
|
||||
})
|
||||
|
||||
if (!sub) return true
|
||||
|
||||
const stripeSubId = sub.stripeSubscriptionId
|
||||
if (stripeSubId && !stripeSubId.startsWith('sub_mock')) {
|
||||
return false
|
||||
}
|
||||
|
||||
// Already on a paid / trial tier locally without a Stripe id (admin override)
|
||||
if (sub.tier !== 'BASIC' && (sub.status === 'ACTIVE' || sub.status === 'TRIALING')) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user