Subscription
The Subscription interface defines the core structure for a user’s subscription record in Firebase Firestore. It encapsulates essential details about the subscription, including its associated plan, status, permissions, and ownership.
Properties
id:stringThe unique identifier for the subscription.plan_id:stringThe ID of the subscription plan (referencing thePlaninterface).status:stringThe current status of the subscription (e.g., ‘active’, ‘canceled’, ’trialing’).permissions:UserPermissionsAn object defining the permissions associated with this subscription, typically used for role-based access control within the subscription.settings?:SubscriptionSettingsAn optional object containing customizable settings specific to this subscription.owner_id:stringThe Firebase User ID (UID) of the user who owns this subscription.
Usage
The Subscription interface is central to managing user subscriptions. It is used by the SubscriptionContext to provide subscription data throughout the application and by various components that display or modify subscription details.
// Example of a Firestore document for a subscription
interface FirestoreSubscriptionDocument {
id: "sub_xyz123";
plan_id: "plan_basic";
status: "active";
permissions: {
"admin": ["read", "write"],
"member": ["read"]
};
settings: {
"name": "My Team Project",
"timezone": "UTC"
};
owner_id: "user_abc456";
}
// In a React component or hook:
import { useSubscription } from '@fireact.dev/app'; // Import the hook
import { type Subscription } from '@fireact.dev/app/types'; // Import the type
function SubscriptionOverview() {
const { subscription, loading, error } = useSubscription();
if (loading) return <div>Loading subscription...</div>;
if (error) return <div>Error: {error.message}</div>;
if (!subscription) return <div>No subscription found.</div>;
return (
<div>
<h2>Subscription: {subscription.settings?.name || subscription.id}</h2>
<p>Plan: {subscription.plan_id}</p>
<p>Status: {subscription.status}</p>
<p>Owner: {subscription.owner_id}</p>
{/* Display permissions or settings */}
</div>
);
}
Related Components/Hooks
useSubscriptionhook: Provides access to the currentSubscriptionobject.SubscriptionDashboardcomponent: Displays details from theSubscriptionobject.SubscriptionSettingscomponent: Modifies thesettingsfield of theSubscription.ChangePlan,CancelSubscription,TransferSubscriptionOwnershipcomponents: Interact with theSubscriptionobject to manage its lifecycle.UserPermissionstype: Defines the structure of thepermissionsfield.SubscriptionSettingstype: Defines the structure of thesettingsfield.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.