Files
better-auth/demo/nextjs/app/dashboard/page.tsx
Bereket Engida 4f56078e4b feat: stripe plugin to handle subscriptions and customers (#1588)
* init

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* feat(stripe): enable subscription support and update pricing plans

* feat(stripe): add Vitest configuration and initial tests for Stripe integration

* feat(stripe): implement setCookieToHeader function and update tests for customer creation and subscription handling

* feat(stripe): add seats support for subscriptions and update related endpoints

* feat(stripe): update schema to include unique referenceId, stripeSubscriptionId, and periodEnd fields

* wip docs

* docs

* docs: imporves

* fix(stripe): update webhook handlers to use correct subscription identification

* refactor(stripe): simplify customer management by storing Stripe customer ID directly on user

* chore(stripe): update package configuration and build setup

- Migrated from tsup to unbuild for build configuration
- Updated package.json with improved export and dependency management
- Added build configuration for better module support
- Removed tsup configuration file

* chore(stripe): update pnpm lockfile dependencies

- Moved `better-auth` from devDependencies to dependencies
- Added `zod` as a direct dependency
- Reorganized package dependencies in the lockfile

* feat(stripe): enhance subscription management and error handling

- Added toast error handling for subscription upgrades in the dashboard
- Updated Stripe price IDs for different plans
- Improved Stripe plugin documentation with beta warning and team subscription details
- Implemented intermediate redirect for checkout success to handle race conditions
- Added support for fetching and updating subscription status after checkout
- Fixed Next.js cookie handling and build configuration

* chore: update snapshot
2025-03-01 01:20:17 +03:00

51 lines
1.4 KiB
TypeScript

import { auth } from "@/lib/auth";
import { headers } from "next/headers";
import { redirect } from "next/navigation";
import UserCard from "./user-card";
import { OrganizationCard } from "./organization-card";
import AccountSwitcher from "@/components/account-switch";
export default async function DashboardPage() {
const [session, activeSessions, deviceSessions, organization, subscriptions] =
await Promise.all([
auth.api.getSession({
headers: await headers(),
}),
auth.api.listSessions({
headers: await headers(),
}),
auth.api.listDeviceSessions({
headers: await headers(),
}),
auth.api.getFullOrganization({
headers: await headers(),
}),
auth.api.listActiveSubscriptions({
headers: await headers(),
}),
]).catch((e) => {
console.log(e);
throw redirect("/sign-in");
});
return (
<div className="w-full">
<div className="flex gap-4 flex-col">
<AccountSwitcher
sessions={JSON.parse(JSON.stringify(deviceSessions))}
/>
<UserCard
session={JSON.parse(JSON.stringify(session))}
activeSessions={JSON.parse(JSON.stringify(activeSessions))}
subscription={subscriptions.find(
(sub) => sub.status === "active" || sub.status === "trialing",
)}
/>
<OrganizationCard
session={JSON.parse(JSON.stringify(session))}
activeOrganization={JSON.parse(JSON.stringify(organization))}
/>
</div>
</div>
);
}