UNPKG

membros-react-sdk

Version:

React authentication library for Membros platform with subscription management and plan-based access control

28 lines 1.26 kB
"use client"; import { jsx as _jsx } from "react/jsx-runtime"; import { useAuth } from "../AuthContext.esm.js"; import { LoadingScreen } from "../components/LoadingScreen.esm.js"; import { AuthScreen } from "../components/AuthScreen.esm.js"; import { InadimplentScreen } from "../components/InadimplentScreen.esm.js"; export function withAuth(Component, options) { return function AuthWrapped(props) { const { user, isLoading, hasActivePlan } = useAuth(); const { useToast, LoadingComponent = LoadingScreen, AuthComponent, InadimplentComponent = InadimplentScreen, requiredPlans } = options || {}; if (isLoading) return _jsx(LoadingComponent, {}); if (!user) { if (AuthComponent) { return _jsx(AuthComponent, {}); } return (_jsx(AuthScreen, { useToast: useToast })); } // Check subscription access using hasActivePlan with provided plan IDs if (requiredPlans && requiredPlans.length > 0) { const hasAccess = hasActivePlan(requiredPlans); if (!hasAccess) return _jsx(InadimplentComponent, {}); } return _jsx(Component, { ...props }); }; } //# sourceMappingURL=withAuth.js.map