mirror of
https://github.com/yusufipk/OpenFrame.git
synced 2026-09-11 09:36:08 +00:00
feat(billing): integrate Stripe for subscription management and billing access
- Added billing-related fields to the User model in the database. - Implemented functions for managing billing access, including trial periods and subscription statuses. - Created new billing utility functions for Stripe integration. - Updated onboarding page to include billing overview and workspace creation eligibility. - Enhanced route access checks to require billing access for certain actions. - Implemented cleanup scripts for expired billing workspaces and associated media. - Updated header component to conditionally show app navigation based on billing access. - Added new migrations for billing-related database changes.
This commit is contained in:
+34
-5
@@ -1,4 +1,5 @@
|
||||
import { auth } from '@/lib/auth';
|
||||
import { buildBillingAccessWhereInput, getBillingOverview } from '@/lib/billing';
|
||||
import { db } from '@/lib/db';
|
||||
import { redirect } from 'next/navigation';
|
||||
import { OnboardingWizard } from './onboarding-wizard';
|
||||
@@ -9,10 +10,28 @@ export default async function OnboardingPage() {
|
||||
redirect('/login');
|
||||
}
|
||||
|
||||
const user = await db.user.findUnique({
|
||||
where: { id: session.user.id },
|
||||
select: { onboardingCompletedAt: true, name: true, email: true },
|
||||
});
|
||||
const [user, billing, creatableWorkspaces] = await Promise.all([
|
||||
db.user.findUnique({
|
||||
where: { id: session.user.id },
|
||||
select: { onboardingCompletedAt: true, name: true, email: true },
|
||||
}),
|
||||
getBillingOverview(session.user.id),
|
||||
db.workspace.findMany({
|
||||
where: {
|
||||
owner: buildBillingAccessWhereInput(),
|
||||
OR: [
|
||||
{ ownerId: session.user.id },
|
||||
{ members: { some: { userId: session.user.id, role: 'ADMIN' } } },
|
||||
],
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
ownerId: true,
|
||||
},
|
||||
orderBy: { name: 'asc' },
|
||||
}),
|
||||
]);
|
||||
|
||||
if (user?.onboardingCompletedAt) {
|
||||
redirect('/dashboard');
|
||||
@@ -20,5 +39,15 @@ export default async function OnboardingPage() {
|
||||
|
||||
const userName = user?.name || user?.email?.split('@')[0] || 'there';
|
||||
|
||||
return <OnboardingWizard userName={userName} />;
|
||||
return (
|
||||
<OnboardingWizard
|
||||
userName={userName}
|
||||
canCreateWorkspace={billing.workspaceCreation.canCreateWorkspace}
|
||||
availableWorkspaces={creatableWorkspaces.map((workspace) => ({
|
||||
id: workspace.id,
|
||||
name: workspace.name,
|
||||
isOwner: workspace.ownerId === session.user.id,
|
||||
}))}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user