@jeanmemory/react
Version:
React SDK for Jean Memory - Build personalized AI chatbots in 5 lines of code
70 lines (69 loc) • 3.35 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.JeanAuthGuard = JeanAuthGuard;
const jsx_runtime_1 = require("react/jsx-runtime");
const provider_1 = require("./provider");
const SignInWithJean_1 = require("./SignInWithJean");
/**
* AuthGuard component that automatically handles authentication state
*
* @example
* ```jsx
* <JeanProvider apiKey="your-key">
* <JeanAuthGuard>
* <YourApp />
* </JeanAuthGuard>
* </JeanProvider>
* ```
*/
function JeanAuthGuard({ children, loadingComponent, signInComponent, fallback, showDefaultSignIn = true }) {
const { isAuthenticated, isLoading, user, apiKey } = (0, provider_1.useJean)();
// Show loading state
if (isLoading) {
return (loadingComponent || ((0, jsx_runtime_1.jsxs)("div", { style: {
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
height: '100vh',
flexDirection: 'column',
gap: '16px'
}, children: [(0, jsx_runtime_1.jsx)("div", { style: { fontSize: '24px' }, children: "\uD83E\uDDE0" }), (0, jsx_runtime_1.jsx)("div", { children: "Connecting to Jean Memory..." })] })));
}
// Show authenticated content
if (isAuthenticated) {
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children });
}
// Show custom fallback if provided
if (fallback) {
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: fallback });
}
// Show custom sign-in component
if (signInComponent) {
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: signInComponent });
}
// Show default sign-in UI
if (showDefaultSignIn) {
return ((0, jsx_runtime_1.jsxs)("div", { style: {
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
height: '100vh',
flexDirection: 'column',
gap: '24px',
padding: '40px',
textAlign: 'center'
}, children: [(0, jsx_runtime_1.jsx)("div", { style: { fontSize: '48px', marginBottom: '16px' }, children: "\uD83E\uDDE0" }), (0, jsx_runtime_1.jsx)("h1", { style: { margin: 0, fontSize: '32px', fontWeight: 'bold' }, children: "Jean Memory" }), (0, jsx_runtime_1.jsx)("p", { style: { margin: 0, fontSize: '18px', color: '#666', maxWidth: '400px' }, children: "Sign in to access your personalized AI that remembers everything" }), (0, jsx_runtime_1.jsx)("div", { style: {
padding: '12px 24px',
fontSize: '16px',
backgroundColor: '#007bff',
color: 'white',
border: 'none',
borderRadius: '8px',
cursor: 'pointer',
fontWeight: 'bold',
display: 'inline-block'
}, children: (0, jsx_runtime_1.jsx)(SignInWithJean_1.SignInWithJean, { apiKey: apiKey, onSuccess: (user) => console.log('✅ Authentication successful:', user.email), onError: (error) => console.error('❌ Authentication failed:', error), children: "Sign In with Jean" }) })] }));
}
// Fallback: show nothing
return null;
}
;