UNPKG

membros-react-sdk

Version:

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

31 lines 1.52 kB
"use strict"; "use client"; Object.defineProperty(exports, "__esModule", { value: true }); exports.withAuth = withAuth; const jsx_runtime_1 = require("react/jsx-runtime"); const AuthContext_1 = require("../AuthContext.cjs"); const LoadingScreen_1 = require("../components/LoadingScreen.cjs"); const AuthScreen_1 = require("../components/AuthScreen.cjs"); const InadimplentScreen_1 = require("../components/InadimplentScreen.cjs"); function withAuth(Component, options) { return function AuthWrapped(props) { const { user, isLoading, hasActivePlan } = (0, AuthContext_1.useAuth)(); const { useToast, LoadingComponent = LoadingScreen_1.LoadingScreen, AuthComponent, InadimplentComponent = InadimplentScreen_1.InadimplentScreen, requiredPlans } = options || {}; if (isLoading) return (0, jsx_runtime_1.jsx)(LoadingComponent, {}); if (!user) { if (AuthComponent) { return (0, jsx_runtime_1.jsx)(AuthComponent, {}); } return ((0, jsx_runtime_1.jsx)(AuthScreen_1.AuthScreen, { useToast: useToast })); } // Check subscription access using hasActivePlan with provided plan IDs if (requiredPlans && requiredPlans.length > 0) { const hasAccess = hasActivePlan(requiredPlans); if (!hasAccess) return (0, jsx_runtime_1.jsx)(InadimplentComponent, {}); } return (0, jsx_runtime_1.jsx)(Component, { ...props }); }; } //# sourceMappingURL=withAuth.js.map