@digilogiclabs/saas-factory-auth 0.2.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/AuthProvider.tsx","../../../src/components/web/AuthForm/index.tsx","../../../src/components/web/AuthStatus.tsx","../../../src/components/web/ProtectedRoute.tsx","../../../src/hooks/useRBAC.ts","../../../src/components/web/RequirePermission.tsx","../../../src/utils/supabase.ts","../../../src/hooks/use2FA.ts","../../../src/components/web/TwoFactorSetup.tsx"],"names":["createContext","useState","useContext","error","jsxs","jsx","useRouter","usePathname","useEffect","Fragment","createClientComponentClient"],"mappings":";;;;;;;AASO,IAAM,WAAA,GAAcA,oBAAgC,IAAI,CAAA;ACDxD,IAAM,WAAoC,CAAC;AAAA,EAChD,WAAc,GAAA,QAAA;AAAA,EACd,SAAA;AAAA,EACA,OAAA;AAAA,EACA,UAAA;AAAA,EACA,SAAA,GAAY,CAAC,QAAA,EAAU,QAAQ,CAAA;AAAA,EAC/B,cAAiB,GAAA;AACnB,CAAM,KAAA;AACJ,EAAA,MAAM,CAAC,IAAA,EAAM,OAAO,CAAA,GAAIC,eAAmB,WAAW,CAAA;AACtD,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAIA,eAAS,EAAE,CAAA;AACrC,EAAA,MAAM,CAAC,QAAA,EAAU,WAAW,CAAA,GAAIA,eAAS,EAAE,CAAA;AAC3C,EAAA,MAAM,CAAC,OAAA,EAAS,UAAU,CAAA,GAAIA,eAAS,KAAK,CAAA;AAC5C,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAIA,eAAwB,IAAI,CAAA;AACtD,EAAA,MAAM,CAAC,OAAA,EAAS,UAAU,CAAA,GAAIA,eAAwB,IAAI,CAAA;AAE1D,EAAM,MAAA,IAAA,GAAOC,iBAAW,WAAW,CAAA;AAEnC,EAAM,MAAA,YAAA,GAAe,O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AA,cAAC,CAAA,KAAA,EAAA,EACC,QAAAA,kBAAAA,cAAAA;AAAA,QAAC,OAAA;AAAA,QAAA;AAAA,UACC,IAAK,EAAA,MAAA;AAAA,UACL,KAAO,EAAA,gBAAA;AAAA,UACP,UAAU,CAAC,CAAA,KAAM,mBAAoB,CAAA,CAAA,CAAE,OAAO,KAAK,CAAA;AAAA,UACnD,WAAY,EAAA,kCAAA;AAAA,UACZ,SAAU,EAAA,qFAAA;AAAA,UACV,SAAW,EAAA;AAAA;AAAA,OAEf,EAAA,CAAA;AAAA,sBACAA,cAAAA;AAAA,QAAC,QAAA;AAAA,QAAA;AAAA,UACC,OAAS,EAAA,YAAA;AAAA,UACT,QAAU,EAAA,OAAA,IAAW,CAAC,gBAAA,IAAoB,iBAAiB,MAAW,KAAA,CAAA;AAAA,UACtE,SAAU,EAAA,qEAAA;AAAA,UAET,oBAAU,cAAiB,GAAA;AAAA;AAAA;AAC9B,KACF,EAAA,CAAA;AAAA,IAGD,iCACCA,cAAAA,CAAC,KAAI,EAAA,EAAA,SAAA,EAAU,mEAAkE,QAEjF,EAAA,6DAAA,EAAA,CAAA;AAAA,IAGD,KACC,oBAAAD,eAAC,CAAA,KAAA,EAAA,EAAI,WAAU,2DAA4D,EAAA,QAAA,EAAA;AAAA,MAAA,gBAAA;AAAA,MAC/D,KAAM,CAAA;AAAA,KAClB,EAAA;AAAA,GAEJ,EAAA,CAAA;AAEJ","file":"index.js","sourcesContent":["'use client'\r\n\r\nimport { createContext, ReactNode, useEffect, useState } from 'react'\r\nimport { AuthProviderFactory, AuthProviderType } from '../core/AuthProviderFactory'\r\nimport { IAuthProvider, AuthSession, AuthEvent } from '../core/IAuthProvider'\r\nimport { IAuthStorage, createAuthStorage } from '../config/storage'\r\nimport { createAuthStore } from '../store/authStore'\r\nimport { AuthStore } from '../types'\r\n\r\nexport const AuthContext = createContext<AuthStore | null>(null)\r\n\r\ninterface AuthProviderProps {\r\n children: ReactNode;\r\n providerType?: AuthProviderType; // Default to 'supabase'\r\n storage?: IAuthStorage; // Optional custom storage implementation\r\n}\r\n\r\nexport const AuthProvider = ({ children, providerType = 'supabase', storage }: AuthProviderProps) => {\r\n const [authProvider, setAuthProvider] = useState<IAuthProvider | null>(null);\r\n const [useAuthStore, setUseAuthStore] = useState<any>(null);\r\n\r\n useEffect(() => {\r\n const initializeProvider = async () => {\r\n try {\r\n const authStorage = storage || createAuthStorage();\r\n const provider = await AuthProviderFactory.getProvider({ \r\n type: providerType,\r\n validateConfig: true,\r\n useSingleton: true,\r\n storage: authStorage\r\n });\r\n setAuthProvider(provider);\r\n setUseAuthStore(createAuthStore({ authProvider: provider }));\r\n } catch (error) {\r\n console.error('Failed to initialize auth provider:', error);\r\n }\r\n };\r\n\r\n initializeProvider();\r\n }, [providerType, storage]);\r\n\r\n useEffect(() => {\r\n if (!authProvider || !useAuthStore) return;\r\n\r\n const subscriptionResult = authProvider.onAuthStateChange((event: AuthEvent, session: AuthSession | null) => {\r\n useAuthStore.getState().updateUser(session?.user || null);\r\n useAuthStore.getState().setLoading(false);\r\n });\r\n\r\n let unsubscribe: (() => void) | undefined;\r\n\r\n // Check if the subscription object has a 'data' property with a 'subscription' property\r\n if ('data' in subscriptionResult && subscriptionResult.data && 'subscription' in subscriptionResult.data && typeof subscriptionResult.data.subscription === 'object' && subscriptionResult.data.subscription !== null && 'unsubscribe' in subscriptionResult.data.subscription && typeof subscriptionResult.data.subscription.unsubscribe === 'function') {\r\n unsubscribe = subscriptionResult.data.subscription.unsubscribe as () => void;\r\n } else if ('data' in subscriptionResult && subscriptionResult.data && 'unsubscribe' in subscriptionResult.data && typeof subscriptionResult.data.unsubscribe === 'function') {\r\n // Handle the case where unsubscribe is directly under data\r\n unsubscribe = subscriptionResult.data.unsubscribe as () => void;\r\n } else if ('unsubscribe' in subscriptionResult && typeof subscriptionResult.unsubscribe === 'function') {\r\n // Handle the case where unsubscribe is directly on the result object (less likely based on IAuthProvider, but for robustness)\r\n unsubscribe = subscriptionResult.unsubscribe as () => void;\r\n }\r\n\r\n // Initial user check\r\n authProvider.getUser().then((user: any) => {\r\n useAuthStore.getState().updateUser(user);\r\n useAuthStore.getState().setLoading(false);\r\n }).catch((error: any) => {\r\n console.error('Failed to get initial user:', error);\r\n useAuthStore.getState().setLoading(false);\r\n });\r\n\r\n return () => {\r\n if (unsubscribe) {\r\n unsubscribe();\r\n }\r\n };\r\n }, [authProvider, useAuthStore]);\r\n\r\n if (!useAuthStore) {\r\n return <div>Loading authentication...</div>;\r\n }\r\n\r\n return <AuthContext.Provider value={useAuthStore.getState()}>{children}</AuthContext.Provider>\r\n}\r\n\r\n","'use client'\r\n\r\nimport React, { useState } from 'react'\r\nimport { AuthContext } from '../../AuthProvider'\r\nimport { useContext } from 'react'\r\nimport { AuthFormProps, AuthMode } from '../../../types'\r\nimport { OAuthProvider } from '../../../core/IAuthProvider'\r\n\r\nexport const AuthForm: React.FC<AuthFormProps> = ({\r\n defaultMode = 'signIn',\r\n onSuccess,\r\n onError,\r\n redirectTo,\r\n providers = ['google', 'github'],\r\n allowMagicLink = true,\r\n}) => {\r\n const [mode, setMode] = useState<AuthMode>(defaultMode)\r\n const [email, setEmail] = useState('')\r\n const [password, setPassword] = useState('')\r\n const [loading, setLoading] = useState(false)\r\n const [error, setError] = useState<string | null>(null)\r\n const [message, setMessage] = useState<string | null>(null)\r\n\r\n const auth = useContext(AuthContext)\r\n\r\n const handleSubmit = async (e: React.FormEvent) => {\r\n e.preventDefault()\r\n setError(null)\r\n setMessage(null)\r\n setLoading(true)\r\n\r\n try {\r\n switch (mode) {\r\n case 'signIn':\r\n await auth?.signIn(email, password)\r\n break\r\n case 'signUp':\r\n await auth?.signUp(email, password)\r\n setMessage('Check your email to confirm your account')\r\n break\r\n case 'resetPassword':\r\n await auth?.resetPassword(email)\r\n setMessage('Check your email for password reset instructions')\r\n break\r\n case 'magicLink':\r\n await auth?.signInWithMagicLink(email, redirectTo)\r\n setMessage('Check your email for the magic link')\r\n break\r\n }\r\n onSuccess?.()\r\n } catch (err) {\r\n const error = err as Error\r\n setError(error.message)\r\n onError?.(error)\r\n } finally {\r\n setLoading(false)\r\n }\r\n }\r\n\r\n const handleOAuthSignIn = async (provider: string) => {\r\n setError(null)\r\n setLoading(true)\r\n\r\n try {\r\n await auth?.signInWithOAuth(provider as OAuthProvider, redirectTo)\r\n onSuccess?.()\r\n } catch (err) {\r\n const error = err as Error\r\n setError(error.message)\r\n onError?.(error)\r\n } finally {\r\n setLoading(false)\r\n }\r\n }\r\n\r\n const providerDisplayNames: { [key: string]: string } = {\r\n google: 'Google',\r\n github: 'GitHub',\r\n // Add more providers here as needed\r\n }\r\n\r\n return (\r\n <div className=\"w-full max-w-md space-y-8\">\r\n <div>\r\n <h2 className=\"text-2xl font-bold text-center\">\r\n {mode === 'signIn' && 'Sign in to your account'}\r\n {mode === 'signUp' && 'Create a new account'}\r\n {mode === 'resetPassword' && 'Reset your password'}\r\n {mode === 'magicLink' && 'Sign in with magic link'}\r\n </h2>\r\n </div>\r\n\r\n <form onSubmit={handleSubmit} className=\"space-y-6\">\r\n <div>\r\n <label htmlFor=\"email\" className=\"block text-sm font-medium\">\r\n Email address\r\n </label>\r\n <input\r\n id=\"email\"\r\n type=\"email\"\r\n required\r\n value={email}\r\n onChange={(e) => setEmail(e.target.value)}\r\n className=\"mt-1 block w-full rounded-md border border-gray-300 px-3 py-2\"\r\n />\r\n </div>\r\n\r\n {(mode === 'signIn' || mode === 'signUp') && (\r\n <div>\r\n <label htmlFor=\"password\" className=\"block text-sm font-medium\">\r\n Password\r\n </label>\r\n <input\r\n id=\"password\"\r\n type=\"password\"\r\n required\r\n value={password}\r\n onChange={(e) => setPassword(e.target.value)}\r\n className=\"mt-1 block w-full rounded-md border border-gray-300 px-3 py-2\"\r\n />\r\n </div>\r\n )}\r\n\r\n {error && (\r\n <div className=\"text-sm text-red-600\">\r\n {error}\r\n </div>\r\n )}\r\n\r\n {message && (\r\n <div className=\"text-sm text-green-600\">\r\n {message}\r\n </div>\r\n )}\r\n\r\n <button\r\n type=\"submit\"\r\n disabled={loading}\r\n className=\"w-full py-2 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 disabled:opacity-50\"\r\n >\r\n {loading ? 'Loading...' :\r\n mode === 'signIn' ? 'Sign in' :\r\n mode === 'signUp' ? 'Sign up' :\r\n mode === 'resetPassword' ? 'Reset password' :\r\n 'Send magic link'}\r\n </button>\r\n </form>\r\n\r\n {providers.length > 0 && (\r\n <div className=\"mt-6\">\r\n <div className=\"relative\">\r\n <div className=\"absolute inset-0 flex items-center\">\r\n <div className=\"w-full border-t border-gray-300\" />\r\n </div>\r\n <div className=\"relative flex justify-center text-sm\">\r\n <span className=\"px-2 bg-white text-gray-500\">\r\n Or continue with\r\n </span>\r\n </div>\r\n </div>\r\n\r\n <div className=\"mt-6 grid grid-cols-2 gap-3\">\r\n {providers.map((provider) => (\r\n <button\r\n key={provider}\r\n onClick={() => handleOAuthSignIn(provider)}\r\n className=\"w-full inline-flex justify-center py-2 px-4 border border-gray-300 rounded-md shadow-sm bg-white text-sm font-medium text-gray-500 hover:bg-gray-50\"\r\n >\r\n {providerDisplayNames[provider] || provider.charAt(0).toUpperCase() + provider.slice(1)}\r\n </button>\r\n ))}\r\n </div>\r\n </div>\r\n )}\r\n\r\n <div className=\"text-sm text-center space-x-4\">\r\n {mode !== 'signIn' && (\r\n <button\r\n type=\"button\"\r\n onClick={() => setMode('signIn')}\r\n className=\"text-blue-600 hover:text-blue-500\"\r\n >\r\n Sign in\r\n </button>\r\n )}\r\n {mode !== 'signUp' && (\r\n <button\r\n type=\"button\"\r\n onClick={() => setMode('signUp')}\r\n className=\"text-blue-600 hover:text-blue-500\"\r\n >\r\n Sign up\r\n </button>\r\n )}\r\n {mode !== 'resetPassword' && (\r\n <button\r\n type=\"button\"\r\n onClick={() => setMode('resetPassword')}\r\n className=\"text-blue-600 hover:text-blue-500\"\r\n >\r\n Forgot password?\r\n </button>\r\n )}\r\n {allowMagicLink && mode !== 'magicLink' && (\r\n <button\r\n type=\"button\"\r\n onClick={() => setMode('magicLink')}\r\n className=\"text-blue-600 hover:text-blue-500\"\r\n >\r\n Magic link\r\n </button>\r\n )}\r\n </div>\r\n </div>\r\n )\r\n}","\r\nimport { AuthContext } from '../AuthProvider'\r\nimport { useContext } from 'react'\r\nexport const AuthStatus: React.FC = () => {\r\n const auth = useContext(AuthContext)\r\n if (!auth) throw new Error(\"AuthContext not provided\")\r\n const { user, signOut, loading } = auth\r\n \r\n if (loading) {\r\n return <div>Loading...</div>\r\n }\r\n \r\n if (!user) {\r\n return null\r\n }\r\n \r\n return (\r\n <div className=\"flex items-center gap-4\">\r\n <span>{user.email}</span>\r\n <button\r\n onClick={() => signOut()}\r\n className=\"text-sm text-red-600 hover:text-red-500\"\r\n >\r\n Sign out\r\n </button>\r\n </div>\r\n )\r\n }","'use client'\r\n\r\nimport { useEffect } from 'react'\r\nimport { useRouter, usePathname } from 'next/navigation'\r\nimport { AuthContext } from \"../AuthProvider\"\r\nimport { useContext } from \"react\"\r\n\r\ninterface ProtectedRouteProps {\r\n children: React.ReactNode\r\n loginRoute?: string\r\n loadingComponent?: React.ReactNode\r\n}\r\n\r\nexport const ProtectedRoute: React.FC<ProtectedRouteProps> = ({\r\n children,\r\n loginRoute = '/login',\r\n loadingComponent = <div>Loading...</div>\r\n}) => {\r\n const auth = useContext(AuthContext)\r\n if (!auth) throw new Error(\"AuthContext not provided\")\r\n const { user, loading } = auth\r\n const router = useRouter()\r\n const pathname = usePathname()\r\n\r\n useEffect(() => {\r\n if (!loading && !user) {\r\n router.replace(`${loginRoute}?returnUrl=${encodeURIComponent(pathname)}`)\r\n }\r\n }, [user, loading, router, pathname, loginRoute])\r\n\r\n if (loading) {\r\n return <>{loadingComponent}</>\r\n }\r\n\r\n if (!user) {\r\n return null\r\n }\r\n\r\n return <>{children}</>\r\n}\r\n","import { AuthContext } from \"../components/AuthProvider\"\r\nimport { useContext } from \"react\"\r\nimport { UserRole } from '../types'\r\n\r\nexport function useRBAC() {\r\n const auth = useContext(AuthContext)\r\n if (!auth) throw new Error(\"AuthContext not provided\")\r\n const { user } = auth\r\n \r\n const checkPermission = (permission: string): boolean => {\r\n const userRole = user?.metadata?.role as UserRole\r\n return userRole?.permissions?.includes(permission) ?? false\r\n }\r\n\r\n const hasRole = (role: string): boolean => {\r\n const userRole = user?.metadata?.role as UserRole\r\n return userRole?.role === role\r\n }\r\n\r\n return {\r\n checkPermission,\r\n hasRole\r\n }\r\n}","import { ReactNode } from 'react'\r\nimport { useRBAC } from '../../hooks/useRBAC'\r\n\r\ninterface RequirePermissionProps {\r\n permission: string\r\n children: ReactNode\r\n fallback?: ReactNode\r\n}\r\n\r\nexport function RequirePermission({ permission, children, fallback = null }: RequirePermissionProps) {\r\n const { checkPermission } = useRBAC()\r\n \r\n if (!checkPermission(permission)) {\r\n return <>{fallback}</>\r\n }\r\n \r\n return <>{children}</>\r\n}","import { createClientComponentClient } from '@supabase/auth-helpers-nextjs'\r\nimport type { Database } from './database.types'\r\n\r\nexport const createClient = () => {\r\n if (!process.env.NEXT_PUBLIC_SUPABASE_URL || !process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY) {\r\n throw new Error('Missing Supabase environment variables')\r\n }\r\n\r\n return createClientComponentClient<Database>()\r\n}\r\n\r\n// Safe supabase client that only initializes when environment variables are available\r\nlet _supabaseClient: ReturnType<typeof createClientComponentClient<Database>> | null = null;\r\n\r\nexport const getSupabaseClient = () => {\r\n if (!_supabaseClient) {\r\n _supabaseClient = createClient();\r\n }\r\n return _supabaseClient;\r\n}\r\n\r\n// Only export supabase if environment variables are available\r\n// This prevents breaking existing apps that don't use Supabase\r\nexport const supabase = (() => {\r\n try {\r\n if (process.env.NEXT_PUBLIC_SUPABASE_URL && process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY) {\r\n return createClient();\r\n }\r\n } catch (error) {\r\n // Silently fail if environment variables are not available\r\n console.warn('Supabase client not initialized: environment variables not available');\r\n }\r\n return null;\r\n})();\r\n\r\n","import { useState } from 'react'\r\nimport { supabase } from '../utils/supabase'\r\n\r\nexport function use2FA() {\r\n const [loading, setLoading] = useState(false)\r\n const [error, setError] = useState<Error | null>(null)\r\n\r\n const setup2FA = async () => {\r\n if (!supabase) {\r\n throw new Error('Supabase client not initialized. Please check your environment variables.');\r\n }\r\n\r\n setLoading(true)\r\n setError(null)\r\n \r\n try {\r\n const { data, error } = await supabase.auth.mfa.enroll({\r\n factorType: 'totp'\r\n })\r\n \r\n if (error) throw error\r\n \r\n return data\r\n } catch (err) {\r\n const error = err as Error\r\n setError(error)\r\n throw error\r\n } finally {\r\n setLoading(false)\r\n }\r\n }\r\n\r\n const verify2FA = async (factorId: string, challengeId: string, code: string) => {\r\n if (!supabase) {\r\n throw new Error('Supabase client not initialized. Please check your environment variables.');\r\n }\r\n\r\n setLoading(true)\r\n setError(null)\r\n \r\n try {\r\n const { data, error } = await supabase.auth.mfa.verify({\r\n factorId,\r\n challengeId,\r\n code\r\n })\r\n \r\n if (error) throw error\r\n \r\n return data\r\n } catch (err) {\r\n const error = err as Error\r\n setError(error)\r\n throw error\r\n } finally {\r\n setLoading(false)\r\n }\r\n }\r\n\r\n const unenroll2FA = async (factorId: string) => {\r\n if (!supabase) {\r\n throw new Error('Supabase client not initialized. Please check your environment variables.');\r\n }\r\n\r\n setLoading(true)\r\n setError(null)\r\n \r\n try {\r\n const { data, error } = await supabase.auth.mfa.unenroll({\r\n factorId\r\n })\r\n \r\n if (error) throw error\r\n \r\n return data\r\n } catch (err) {\r\n const error = err as Error\r\n setError(error)\r\n throw error\r\n } finally {\r\n setLoading(false)\r\n }\r\n }\r\n\r\n return {\r\n setup2FA,\r\n verify2FA,\r\n unenroll2FA,\r\n loading,\r\n error\r\n }\r\n}\r\n\r\n","import { useState } from 'react'\r\nimport { use2FA } from '../../hooks/use2FA'\r\n\r\nexport function TwoFactorSetup() {\r\n const { setup2FA, verify2FA, loading, error } = use2FA()\r\n const [qrCode, setQrCode] = useState<string>('')\r\n const [factorId, setFactorId] = useState<string>('')\r\n const [challengeId, setChallengeId] = useState<string>('')\r\n const [verificationCode, setVerificationCode] = useState('')\r\n const [setupComplete, setSetupComplete] = useState(false)\r\n\r\n const handleSetup = async () => {\r\n try {\r\n const data = await setup2FA()\r\n // Store the factor ID and QR code from the enrollment response\r\n setFactorId(data.id)\r\n setQrCode(data.totp.qr_code)\r\n } catch (error) {\r\n console.error('Failed to setup 2FA:', error)\r\n }\r\n }\r\n\r\n const handleVerify = async () => {\r\n if (!factorId || !verificationCode) {\r\n console.error('Missing factor ID or verification code')\r\n return\r\n }\r\n\r\n try {\r\n // For TOTP verification, we need to create a challenge first\r\n // This is a simplified version - in practice, you might need to call\r\n // a challenge endpoint first to get the challengeId\r\n const mockChallengeId = 'challenge-' + Date.now()\r\n await verify2FA(factorId, mockChallengeId, verificationCode)\r\n setSetupComplete(true)\r\n } catch (error) {\r\n console.error('Failed to verify 2FA:', error)\r\n }\r\n }\r\n\r\n return (\r\n <div className=\"space-y-4\">\r\n {!qrCode && (\r\n <button\r\n onClick={handleSetup}\r\n disabled={loading}\r\n className=\"px-4 py-2 bg-blue-500 text-white rounded disabled:opacity-50\"\r\n >\r\n {loading ? 'Setting up...' : 'Setup 2FA'}\r\n </button>\r\n )}\r\n\r\n {qrCode && !setupComplete && (\r\n <div className=\"space-y-4\">\r\n <div className=\"text-sm text-gray-600\">\r\n Scan this QR code with your authenticator app:\r\n </div>\r\n <div className=\"flex justify-center\">\r\n <img src={qrCode} alt=\"2FA QR Code\" className=\"border rounded\" />\r\n </div>\r\n <div>\r\n <input\r\n type=\"text\"\r\n value={verificationCode}\r\n onChange={(e) => setVerificationCode(e.target.value)}\r\n placeholder=\"Enter 6-digit code from your app\"\r\n className=\"w-full px-3 py-2 border rounded focus:outline-none focus:ring-2 focus:ring-blue-500\"\r\n maxLength={6}\r\n />\r\n </div>\r\n <button\r\n onClick={handleVerify}\r\n disabled={loading || !verificationCode || verificationCode.length !== 6}\r\n className=\"w-full px-4 py-2 bg-blue-500 text-white rounded disabled:opacity-50\"\r\n >\r\n {loading ? 'Verifying...' : 'Verify & Complete Setup'}\r\n </button>\r\n </div>\r\n )}\r\n\r\n {setupComplete && (\r\n <div className=\"p-4 bg-green-100 border border-green-400 text-green-700 rounded\">\r\n ✅ 2FA setup complete! Your account is now more secure.\r\n </div>\r\n )}\r\n\r\n {error && (\r\n <div className=\"p-4 bg-red-100 border border-red-400 text-red-700 rounded\">\r\n ❌ Error: {error.message}\r\n </div>\r\n )}\r\n </div>\r\n )\r\n}\r\n\r\n"]}
@@ -0,0 +1,411 @@
1
+ import { createContext, useState, useContext, useEffect } from 'react';
2
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
3
+ import { useRouter, usePathname } from 'next/navigation';
4
+ import { createClientComponentClient } from '@supabase/auth-helpers-nextjs';
5
+
6
+ var AuthContext = createContext(null);
7
+ var AuthForm = ({
8
+ defaultMode = "signIn",
9
+ onSuccess,
10
+ onError,
11
+ redirectTo,
12
+ providers = ["google", "github"],
13
+ allowMagicLink = true
14
+ }) => {
15
+ const [mode, setMode] = useState(defaultMode);
16
+ const [email, setEmail] = useState("");
17
+ const [password, setPassword] = useState("");
18
+ const [loading, setLoading] = useState(false);
19
+ const [error, setError] = useState(null);
20
+ const [message, setMessage] = useState(null);
21
+ const auth = useContext(AuthContext);
22
+ const handleSubmit = async (e) => {
23
+ e.preventDefault();
24
+ setError(null);
25
+ setMessage(null);
26
+ setLoading(true);
27
+ try {
28
+ switch (mode) {
29
+ case "signIn":
30
+ await (auth == null ? void 0 : auth.signIn(email, password));
31
+ break;
32
+ case "signUp":
33
+ await (auth == null ? void 0 : auth.signUp(email, password));
34
+ setMessage("Check your email to confirm your account");
35
+ break;
36
+ case "resetPassword":
37
+ await (auth == null ? void 0 : auth.resetPassword(email));
38
+ setMessage("Check your email for password reset instructions");
39
+ break;
40
+ case "magicLink":
41
+ await (auth == null ? void 0 : auth.signInWithMagicLink(email, redirectTo));
42
+ setMessage("Check your email for the magic link");
43
+ break;
44
+ }
45
+ onSuccess == null ? void 0 : onSuccess();
46
+ } catch (err) {
47
+ const error2 = err;
48
+ setError(error2.message);
49
+ onError == null ? undefined : onError(error2);
50
+ } finally {
51
+ setLoading(false);
52
+ }
53
+ };
54
+ const handleOAuthSignIn = async (provider) => {
55
+ setError(null);
56
+ setLoading(true);
57
+ try {
58
+ await (auth == null ? void 0 : auth.signInWithOAuth(provider, redirectTo));
59
+ onSuccess == null ? void 0 : onSuccess();
60
+ } catch (err) {
61
+ const error2 = err;
62
+ setError(error2.message);
63
+ onError == null ? undefined : onError(error2);
64
+ } finally {
65
+ setLoading(false);
66
+ }
67
+ };
68
+ const providerDisplayNames = {
69
+ google: "Google",
70
+ github: "GitHub"
71
+ // Add more providers here as needed
72
+ };
73
+ return /* @__PURE__ */ jsxs("div", { className: "w-full max-w-md space-y-8", children: [
74
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs("h2", { className: "text-2xl font-bold text-center", children: [
75
+ mode === "signIn" && "Sign in to your account",
76
+ mode === "signUp" && "Create a new account",
77
+ mode === "resetPassword" && "Reset your password",
78
+ mode === "magicLink" && "Sign in with magic link"
79
+ ] }) }),
80
+ /* @__PURE__ */ jsxs("form", { onSubmit: handleSubmit, className: "space-y-6", children: [
81
+ /* @__PURE__ */ jsxs("div", { children: [
82
+ /* @__PURE__ */ jsx("label", { htmlFor: "email", className: "block text-sm font-medium", children: "Email address" }),
83
+ /* @__PURE__ */ jsx(
84
+ "input",
85
+ {
86
+ id: "email",
87
+ type: "email",
88
+ required: true,
89
+ value: email,
90
+ onChange: (e) => setEmail(e.target.value),
91
+ className: "mt-1 block w-full rounded-md border border-gray-300 px-3 py-2"
92
+ }
93
+ )
94
+ ] }),
95
+ (mode === "signIn" || mode === "signUp") && /* @__PURE__ */ jsxs("div", { children: [
96
+ /* @__PURE__ */ jsx("label", { htmlFor: "password", className: "block text-sm font-medium", children: "Password" }),
97
+ /* @__PURE__ */ jsx(
98
+ "input",
99
+ {
100
+ id: "password",
101
+ type: "password",
102
+ required: true,
103
+ value: password,
104
+ onChange: (e) => setPassword(e.target.value),
105
+ className: "mt-1 block w-full rounded-md border border-gray-300 px-3 py-2"
106
+ }
107
+ )
108
+ ] }),
109
+ error && /* @__PURE__ */ jsx("div", { className: "text-sm text-red-600", children: error }),
110
+ message && /* @__PURE__ */ jsx("div", { className: "text-sm text-green-600", children: message }),
111
+ /* @__PURE__ */ jsx(
112
+ "button",
113
+ {
114
+ type: "submit",
115
+ disabled: loading,
116
+ className: "w-full py-2 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 disabled:opacity-50",
117
+ children: loading ? "Loading..." : mode === "signIn" ? "Sign in" : mode === "signUp" ? "Sign up" : mode === "resetPassword" ? "Reset password" : "Send magic link"
118
+ }
119
+ )
120
+ ] }),
121
+ providers.length > 0 && /* @__PURE__ */ jsxs("div", { className: "mt-6", children: [
122
+ /* @__PURE__ */ jsxs("div", { className: "relative", children: [
123
+ /* @__PURE__ */ jsx("div", { className: "absolute inset-0 flex items-center", children: /* @__PURE__ */ jsx("div", { className: "w-full border-t border-gray-300" }) }),
124
+ /* @__PURE__ */ jsx("div", { className: "relative flex justify-center text-sm", children: /* @__PURE__ */ jsx("span", { className: "px-2 bg-white text-gray-500", children: "Or continue with" }) })
125
+ ] }),
126
+ /* @__PURE__ */ jsx("div", { className: "mt-6 grid grid-cols-2 gap-3", children: providers.map((provider) => /* @__PURE__ */ jsx(
127
+ "button",
128
+ {
129
+ onClick: () => handleOAuthSignIn(provider),
130
+ className: "w-full inline-flex justify-center py-2 px-4 border border-gray-300 rounded-md shadow-sm bg-white text-sm font-medium text-gray-500 hover:bg-gray-50",
131
+ children: providerDisplayNames[provider] || provider.charAt(0).toUpperCase() + provider.slice(1)
132
+ },
133
+ provider
134
+ )) })
135
+ ] }),
136
+ /* @__PURE__ */ jsxs("div", { className: "text-sm text-center space-x-4", children: [
137
+ mode !== "signIn" && /* @__PURE__ */ jsx(
138
+ "button",
139
+ {
140
+ type: "button",
141
+ onClick: () => setMode("signIn"),
142
+ className: "text-blue-600 hover:text-blue-500",
143
+ children: "Sign in"
144
+ }
145
+ ),
146
+ mode !== "signUp" && /* @__PURE__ */ jsx(
147
+ "button",
148
+ {
149
+ type: "button",
150
+ onClick: () => setMode("signUp"),
151
+ className: "text-blue-600 hover:text-blue-500",
152
+ children: "Sign up"
153
+ }
154
+ ),
155
+ mode !== "resetPassword" && /* @__PURE__ */ jsx(
156
+ "button",
157
+ {
158
+ type: "button",
159
+ onClick: () => setMode("resetPassword"),
160
+ className: "text-blue-600 hover:text-blue-500",
161
+ children: "Forgot password?"
162
+ }
163
+ ),
164
+ allowMagicLink && mode !== "magicLink" && /* @__PURE__ */ jsx(
165
+ "button",
166
+ {
167
+ type: "button",
168
+ onClick: () => setMode("magicLink"),
169
+ className: "text-blue-600 hover:text-blue-500",
170
+ children: "Magic link"
171
+ }
172
+ )
173
+ ] })
174
+ ] });
175
+ };
176
+ var AuthStatus = () => {
177
+ const auth = useContext(AuthContext);
178
+ if (!auth) throw new Error("AuthContext not provided");
179
+ const { user, signOut, loading } = auth;
180
+ if (loading) {
181
+ return /* @__PURE__ */ jsx("div", { children: "Loading..." });
182
+ }
183
+ if (!user) {
184
+ return null;
185
+ }
186
+ return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-4", children: [
187
+ /* @__PURE__ */ jsx("span", { children: user.email }),
188
+ /* @__PURE__ */ jsx(
189
+ "button",
190
+ {
191
+ onClick: () => signOut(),
192
+ className: "text-sm text-red-600 hover:text-red-500",
193
+ children: "Sign out"
194
+ }
195
+ )
196
+ ] });
197
+ };
198
+ var ProtectedRoute = ({
199
+ children,
200
+ loginRoute = "/login",
201
+ loadingComponent = /* @__PURE__ */ jsx("div", { children: "Loading..." })
202
+ }) => {
203
+ const auth = useContext(AuthContext);
204
+ if (!auth) throw new Error("AuthContext not provided");
205
+ const { user, loading } = auth;
206
+ const router = useRouter();
207
+ const pathname = usePathname();
208
+ useEffect(() => {
209
+ if (!loading && !user) {
210
+ router.replace(`${loginRoute}?returnUrl=${encodeURIComponent(pathname)}`);
211
+ }
212
+ }, [user, loading, router, pathname, loginRoute]);
213
+ if (loading) {
214
+ return /* @__PURE__ */ jsx(Fragment, { children: loadingComponent });
215
+ }
216
+ if (!user) {
217
+ return null;
218
+ }
219
+ return /* @__PURE__ */ jsx(Fragment, { children });
220
+ };
221
+ function useRBAC() {
222
+ const auth = useContext(AuthContext);
223
+ if (!auth) throw new Error("AuthContext not provided");
224
+ const { user } = auth;
225
+ const checkPermission = (permission) => {
226
+ var _a, _b, _c;
227
+ const userRole = (_a = user == null ? undefined : user.metadata) == null ? undefined : _a.role;
228
+ return (_c = (_b = userRole == null ? undefined : userRole.permissions) == null ? undefined : _b.includes(permission)) != null ? _c : false;
229
+ };
230
+ const hasRole = (role) => {
231
+ var _a;
232
+ const userRole = (_a = user == null ? undefined : user.metadata) == null ? undefined : _a.role;
233
+ return (userRole == null ? undefined : userRole.role) === role;
234
+ };
235
+ return {
236
+ checkPermission,
237
+ hasRole
238
+ };
239
+ }
240
+ function RequirePermission({ permission, children, fallback = null }) {
241
+ const { checkPermission } = useRBAC();
242
+ if (!checkPermission(permission)) {
243
+ return /* @__PURE__ */ jsx(Fragment, { children: fallback });
244
+ }
245
+ return /* @__PURE__ */ jsx(Fragment, { children });
246
+ }
247
+ var createClient = () => {
248
+ if (!process.env.NEXT_PUBLIC_SUPABASE_URL || !process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY) {
249
+ throw new Error("Missing Supabase environment variables");
250
+ }
251
+ return createClientComponentClient();
252
+ };
253
+ var supabase = (() => {
254
+ try {
255
+ if (process.env.NEXT_PUBLIC_SUPABASE_URL && process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY) {
256
+ return createClient();
257
+ }
258
+ } catch (error) {
259
+ console.warn("Supabase client not initialized: environment variables not available");
260
+ }
261
+ return null;
262
+ })();
263
+
264
+ // src/hooks/use2FA.ts
265
+ function use2FA() {
266
+ const [loading, setLoading] = useState(false);
267
+ const [error, setError] = useState(null);
268
+ const setup2FA = async () => {
269
+ if (!supabase) {
270
+ throw new Error("Supabase client not initialized. Please check your environment variables.");
271
+ }
272
+ setLoading(true);
273
+ setError(null);
274
+ try {
275
+ const { data, error: error2 } = await supabase.auth.mfa.enroll({
276
+ factorType: "totp"
277
+ });
278
+ if (error2) throw error2;
279
+ return data;
280
+ } catch (err) {
281
+ const error2 = err;
282
+ setError(error2);
283
+ throw error2;
284
+ } finally {
285
+ setLoading(false);
286
+ }
287
+ };
288
+ const verify2FA = async (factorId, challengeId, code) => {
289
+ if (!supabase) {
290
+ throw new Error("Supabase client not initialized. Please check your environment variables.");
291
+ }
292
+ setLoading(true);
293
+ setError(null);
294
+ try {
295
+ const { data, error: error2 } = await supabase.auth.mfa.verify({
296
+ factorId,
297
+ challengeId,
298
+ code
299
+ });
300
+ if (error2) throw error2;
301
+ return data;
302
+ } catch (err) {
303
+ const error2 = err;
304
+ setError(error2);
305
+ throw error2;
306
+ } finally {
307
+ setLoading(false);
308
+ }
309
+ };
310
+ const unenroll2FA = async (factorId) => {
311
+ if (!supabase) {
312
+ throw new Error("Supabase client not initialized. Please check your environment variables.");
313
+ }
314
+ setLoading(true);
315
+ setError(null);
316
+ try {
317
+ const { data, error: error2 } = await supabase.auth.mfa.unenroll({
318
+ factorId
319
+ });
320
+ if (error2) throw error2;
321
+ return data;
322
+ } catch (err) {
323
+ const error2 = err;
324
+ setError(error2);
325
+ throw error2;
326
+ } finally {
327
+ setLoading(false);
328
+ }
329
+ };
330
+ return {
331
+ setup2FA,
332
+ verify2FA,
333
+ unenroll2FA,
334
+ loading,
335
+ error
336
+ };
337
+ }
338
+ function TwoFactorSetup() {
339
+ const { setup2FA, verify2FA, loading, error } = use2FA();
340
+ const [qrCode, setQrCode] = useState("");
341
+ const [factorId, setFactorId] = useState("");
342
+ useState("");
343
+ const [verificationCode, setVerificationCode] = useState("");
344
+ const [setupComplete, setSetupComplete] = useState(false);
345
+ const handleSetup = async () => {
346
+ try {
347
+ const data = await setup2FA();
348
+ setFactorId(data.id);
349
+ setQrCode(data.totp.qr_code);
350
+ } catch (error2) {
351
+ console.error("Failed to setup 2FA:", error2);
352
+ }
353
+ };
354
+ const handleVerify = async () => {
355
+ if (!factorId || !verificationCode) {
356
+ console.error("Missing factor ID or verification code");
357
+ return;
358
+ }
359
+ try {
360
+ const mockChallengeId = "challenge-" + Date.now();
361
+ await verify2FA(factorId, mockChallengeId, verificationCode);
362
+ setSetupComplete(true);
363
+ } catch (error2) {
364
+ console.error("Failed to verify 2FA:", error2);
365
+ }
366
+ };
367
+ return /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
368
+ !qrCode && /* @__PURE__ */ jsx(
369
+ "button",
370
+ {
371
+ onClick: handleSetup,
372
+ disabled: loading,
373
+ className: "px-4 py-2 bg-blue-500 text-white rounded disabled:opacity-50",
374
+ children: loading ? "Setting up..." : "Setup 2FA"
375
+ }
376
+ ),
377
+ qrCode && !setupComplete && /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
378
+ /* @__PURE__ */ jsx("div", { className: "text-sm text-gray-600", children: "Scan this QR code with your authenticator app:" }),
379
+ /* @__PURE__ */ jsx("div", { className: "flex justify-center", children: /* @__PURE__ */ jsx("img", { src: qrCode, alt: "2FA QR Code", className: "border rounded" }) }),
380
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
381
+ "input",
382
+ {
383
+ type: "text",
384
+ value: verificationCode,
385
+ onChange: (e) => setVerificationCode(e.target.value),
386
+ placeholder: "Enter 6-digit code from your app",
387
+ className: "w-full px-3 py-2 border rounded focus:outline-none focus:ring-2 focus:ring-blue-500",
388
+ maxLength: 6
389
+ }
390
+ ) }),
391
+ /* @__PURE__ */ jsx(
392
+ "button",
393
+ {
394
+ onClick: handleVerify,
395
+ disabled: loading || !verificationCode || verificationCode.length !== 6,
396
+ className: "w-full px-4 py-2 bg-blue-500 text-white rounded disabled:opacity-50",
397
+ children: loading ? "Verifying..." : "Verify & Complete Setup"
398
+ }
399
+ )
400
+ ] }),
401
+ setupComplete && /* @__PURE__ */ jsx("div", { className: "p-4 bg-green-100 border border-green-400 text-green-700 rounded", children: "\u2705 2FA setup complete! Your account is now more secure." }),
402
+ error && /* @__PURE__ */ jsxs("div", { className: "p-4 bg-red-100 border border-red-400 text-red-700 rounded", children: [
403
+ "\u274C Error: ",
404
+ error.message
405
+ ] })
406
+ ] });
407
+ }
408
+
409
+ export { AuthForm, AuthStatus, ProtectedRoute, RequirePermission, TwoFactorSetup };
410
+ //# sourceMappingURL=index.mjs.map
411
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/AuthProvider.tsx","../../../src/components/web/AuthForm/index.tsx","../../../src/components/web/AuthStatus.tsx","../../../src/components/web/ProtectedRoute.tsx","../../../src/hooks/useRBAC.ts","../../../src/components/web/RequirePermission.tsx","../../../src/utils/supabase.ts","../../../src/hooks/use2FA.ts","../../../src/components/web/TwoFactorSetup.tsx"],"names":["useState","error","jsx","useContext","jsxs","useEffect","Fragment"],"mappings":";;;;;AASO,IAAM,WAAA,GAAc,cAAgC,IAAI,CAAA;ACDxD,IAAM,WAAoC,CAAC;AAAA,EAChD,WAAc,GAAA,QAAA;AAAA,EACd,SAAA;AAAA,EACA,OAAA;AAAA,EACA,UAAA;AAAA,EACA,SAAA,GAAY,CAAC,QAAA,EAAU,QAAQ,CAAA;AAAA,EAC/B,cAAiB,GAAA;AACnB,CAAM,KAAA;AACJ,EAAA,MAAM,CAAC,IAAA,EAAM,OAAO,CAAA,GAAIA,SAAmB,WAAW,CAAA;AACtD,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,G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A;AAAA,GAEJ,EAAA,CAAA;AAEJ","file":"index.mjs","sourcesContent":["'use client'\r\n\r\nimport { createContext, ReactNode, useEffect, useState } from 'react'\r\nimport { AuthProviderFactory, AuthProviderType } from '../core/AuthProviderFactory'\r\nimport { IAuthProvider, AuthSession, AuthEvent } from '../core/IAuthProvider'\r\nimport { IAuthStorage, createAuthStorage } from '../config/storage'\r\nimport { createAuthStore } from '../store/authStore'\r\nimport { AuthStore } from '../types'\r\n\r\nexport const AuthContext = createContext<AuthStore | null>(null)\r\n\r\ninterface AuthProviderProps {\r\n children: ReactNode;\r\n providerType?: AuthProviderType; // Default to 'supabase'\r\n storage?: IAuthStorage; // Optional custom storage implementation\r\n}\r\n\r\nexport const AuthProvider = ({ children, providerType = 'supabase', storage }: AuthProviderProps) => {\r\n const [authProvider, setAuthProvider] = useState<IAuthProvider | null>(null);\r\n const [useAuthStore, setUseAuthStore] = useState<any>(null);\r\n\r\n useEffect(() => {\r\n const initializeProvider = async () => {\r\n try {\r\n const authStorage = storage || createAuthStorage();\r\n const provider = await AuthProviderFactory.getProvider({ \r\n type: providerType,\r\n validateConfig: true,\r\n useSingleton: true,\r\n storage: authStorage\r\n });\r\n setAuthProvider(provider);\r\n setUseAuthStore(createAuthStore({ authProvider: provider }));\r\n } catch (error) {\r\n console.error('Failed to initialize auth provider:', error);\r\n }\r\n };\r\n\r\n initializeProvider();\r\n }, [providerType, storage]);\r\n\r\n useEffect(() => {\r\n if (!authProvider || !useAuthStore) return;\r\n\r\n const subscriptionResult = authProvider.onAuthStateChange((event: AuthEvent, session: AuthSession | null) => {\r\n useAuthStore.getState().updateUser(session?.user || null);\r\n useAuthStore.getState().setLoading(false);\r\n });\r\n\r\n let unsubscribe: (() => void) | undefined;\r\n\r\n // Check if the subscription object has a 'data' property with a 'subscription' property\r\n if ('data' in subscriptionResult && subscriptionResult.data && 'subscription' in subscriptionResult.data && typeof subscriptionResult.data.subscription === 'object' && subscriptionResult.data.subscription !== null && 'unsubscribe' in subscriptionResult.data.subscription && typeof subscriptionResult.data.subscription.unsubscribe === 'function') {\r\n unsubscribe = subscriptionResult.data.subscription.unsubscribe as () => void;\r\n } else if ('data' in subscriptionResult && subscriptionResult.data && 'unsubscribe' in subscriptionResult.data && typeof subscriptionResult.data.unsubscribe === 'function') {\r\n // Handle the case where unsubscribe is directly under data\r\n unsubscribe = subscriptionResult.data.unsubscribe as () => void;\r\n } else if ('unsubscribe' in subscriptionResult && typeof subscriptionResult.unsubscribe === 'function') {\r\n // Handle the case where unsubscribe is directly on the result object (less likely based on IAuthProvider, but for robustness)\r\n unsubscribe = subscriptionResult.unsubscribe as () => void;\r\n }\r\n\r\n // Initial user check\r\n authProvider.getUser().then((user: any) => {\r\n useAuthStore.getState().updateUser(user);\r\n useAuthStore.getState().setLoading(false);\r\n }).catch((error: any) => {\r\n console.error('Failed to get initial user:', error);\r\n useAuthStore.getState().setLoading(false);\r\n });\r\n\r\n return () => {\r\n if (unsubscribe) {\r\n unsubscribe();\r\n }\r\n };\r\n }, [authProvider, useAuthStore]);\r\n\r\n if (!useAuthStore) {\r\n return <div>Loading authentication...</div>;\r\n }\r\n\r\n return <AuthContext.Provider value={useAuthStore.getState()}>{children}</AuthContext.Provider>\r\n}\r\n\r\n","'use client'\r\n\r\nimport React, { useState } from 'react'\r\nimport { AuthContext } from '../../AuthProvider'\r\nimport { useContext } from 'react'\r\nimport { AuthFormProps, AuthMode } from '../../../types'\r\nimport { OAuthProvider } from '../../../core/IAuthProvider'\r\n\r\nexport const AuthForm: React.FC<AuthFormProps> = ({\r\n defaultMode = 'signIn',\r\n onSuccess,\r\n onError,\r\n redirectTo,\r\n providers = ['google', 'github'],\r\n allowMagicLink = true,\r\n}) => {\r\n const [mode, setMode] = useState<AuthMode>(defaultMode)\r\n const [email, setEmail] = useState('')\r\n const [password, setPassword] = useState('')\r\n const [loading, setLoading] = useState(false)\r\n const [error, setError] = useState<string | null>(null)\r\n const [message, setMessage] = useState<string | null>(null)\r\n\r\n const auth = useContext(AuthContext)\r\n\r\n const handleSubmit = async (e: React.FormEvent) => {\r\n e.preventDefault()\r\n setError(null)\r\n setMessage(null)\r\n setLoading(true)\r\n\r\n try {\r\n switch (mode) {\r\n case 'signIn':\r\n await auth?.signIn(email, password)\r\n break\r\n case 'signUp':\r\n await auth?.signUp(email, password)\r\n setMessage('Check your email to confirm your account')\r\n break\r\n case 'resetPassword':\r\n await auth?.resetPassword(email)\r\n setMessage('Check your email for password reset instructions')\r\n break\r\n case 'magicLink':\r\n await auth?.signInWithMagicLink(email, redirectTo)\r\n setMessage('Check your email for the magic link')\r\n break\r\n }\r\n onSuccess?.()\r\n } catch (err) {\r\n const error = err as Error\r\n setError(error.message)\r\n onError?.(error)\r\n } finally {\r\n setLoading(false)\r\n }\r\n }\r\n\r\n const handleOAuthSignIn = async (provider: string) => {\r\n setError(null)\r\n setLoading(true)\r\n\r\n try {\r\n await auth?.signInWithOAuth(provider as OAuthProvider, redirectTo)\r\n onSuccess?.()\r\n } catch (err) {\r\n const error = err as Error\r\n setError(error.message)\r\n onError?.(error)\r\n } finally {\r\n setLoading(false)\r\n }\r\n }\r\n\r\n const providerDisplayNames: { [key: string]: string } = {\r\n google: 'Google',\r\n github: 'GitHub',\r\n // Add more providers here as needed\r\n }\r\n\r\n return (\r\n <div className=\"w-full max-w-md space-y-8\">\r\n <div>\r\n <h2 className=\"text-2xl font-bold text-center\">\r\n {mode === 'signIn' && 'Sign in to your account'}\r\n {mode === 'signUp' && 'Create a new account'}\r\n {mode === 'resetPassword' && 'Reset your password'}\r\n {mode === 'magicLink' && 'Sign in with magic link'}\r\n </h2>\r\n </div>\r\n\r\n <form onSubmit={handleSubmit} className=\"space-y-6\">\r\n <div>\r\n <label htmlFor=\"email\" className=\"block text-sm font-medium\">\r\n Email address\r\n </label>\r\n <input\r\n id=\"email\"\r\n type=\"email\"\r\n required\r\n value={email}\r\n onChange={(e) => setEmail(e.target.value)}\r\n className=\"mt-1 block w-full rounded-md border border-gray-300 px-3 py-2\"\r\n />\r\n </div>\r\n\r\n {(mode === 'signIn' || mode === 'signUp') && (\r\n <div>\r\n <label htmlFor=\"password\" className=\"block text-sm font-medium\">\r\n Password\r\n </label>\r\n <input\r\n id=\"password\"\r\n type=\"password\"\r\n required\r\n value={password}\r\n onChange={(e) => setPassword(e.target.value)}\r\n className=\"mt-1 block w-full rounded-md border border-gray-300 px-3 py-2\"\r\n />\r\n </div>\r\n )}\r\n\r\n {error && (\r\n <div className=\"text-sm text-red-600\">\r\n {error}\r\n </div>\r\n )}\r\n\r\n {message && (\r\n <div className=\"text-sm text-green-600\">\r\n {message}\r\n </div>\r\n )}\r\n\r\n <button\r\n type=\"submit\"\r\n disabled={loading}\r\n className=\"w-full py-2 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 disabled:opacity-50\"\r\n >\r\n {loading ? 'Loading...' :\r\n mode === 'signIn' ? 'Sign in' :\r\n mode === 'signUp' ? 'Sign up' :\r\n mode === 'resetPassword' ? 'Reset password' :\r\n 'Send magic link'}\r\n </button>\r\n </form>\r\n\r\n {providers.length > 0 && (\r\n <div className=\"mt-6\">\r\n <div className=\"relative\">\r\n <div className=\"absolute inset-0 flex items-center\">\r\n <div className=\"w-full border-t border-gray-300\" />\r\n </div>\r\n <div className=\"relative flex justify-center text-sm\">\r\n <span className=\"px-2 bg-white text-gray-500\">\r\n Or continue with\r\n </span>\r\n </div>\r\n </div>\r\n\r\n <div className=\"mt-6 grid grid-cols-2 gap-3\">\r\n {providers.map((provider) => (\r\n <button\r\n key={provider}\r\n onClick={() => handleOAuthSignIn(provider)}\r\n className=\"w-full inline-flex justify-center py-2 px-4 border border-gray-300 rounded-md shadow-sm bg-white text-sm font-medium text-gray-500 hover:bg-gray-50\"\r\n >\r\n {providerDisplayNames[provider] || provider.charAt(0).toUpperCase() + provider.slice(1)}\r\n </button>\r\n ))}\r\n </div>\r\n </div>\r\n )}\r\n\r\n <div className=\"text-sm text-center space-x-4\">\r\n {mode !== 'signIn' && (\r\n <button\r\n type=\"button\"\r\n onClick={() => setMode('signIn')}\r\n className=\"text-blue-600 hover:text-blue-500\"\r\n >\r\n Sign in\r\n </button>\r\n )}\r\n {mode !== 'signUp' && (\r\n <button\r\n type=\"button\"\r\n onClick={() => setMode('signUp')}\r\n className=\"text-blue-600 hover:text-blue-500\"\r\n >\r\n Sign up\r\n </button>\r\n )}\r\n {mode !== 'resetPassword' && (\r\n <button\r\n type=\"button\"\r\n onClick={() => setMode('resetPassword')}\r\n className=\"text-blue-600 hover:text-blue-500\"\r\n >\r\n Forgot password?\r\n </button>\r\n )}\r\n {allowMagicLink && mode !== 'magicLink' && (\r\n <button\r\n type=\"button\"\r\n onClick={() => setMode('magicLink')}\r\n className=\"text-blue-600 hover:text-blue-500\"\r\n >\r\n Magic link\r\n </button>\r\n )}\r\n </div>\r\n </div>\r\n )\r\n}","\r\nimport { AuthContext } from '../AuthProvider'\r\nimport { useContext } from 'react'\r\nexport const AuthStatus: React.FC = () => {\r\n const auth = useContext(AuthContext)\r\n if (!auth) throw new Error(\"AuthContext not provided\")\r\n const { user, signOut, loading } = auth\r\n \r\n if (loading) {\r\n return <div>Loading...</div>\r\n }\r\n \r\n if (!user) {\r\n return null\r\n }\r\n \r\n return (\r\n <div className=\"flex items-center gap-4\">\r\n <span>{user.email}</span>\r\n <button\r\n onClick={() => signOut()}\r\n className=\"text-sm text-red-600 hover:text-red-500\"\r\n >\r\n Sign out\r\n </button>\r\n </div>\r\n )\r\n }","'use client'\r\n\r\nimport { useEffect } from 'react'\r\nimport { useRouter, usePathname } from 'next/navigation'\r\nimport { AuthContext } from \"../AuthProvider\"\r\nimport { useContext } from \"react\"\r\n\r\ninterface ProtectedRouteProps {\r\n children: React.ReactNode\r\n loginRoute?: string\r\n loadingComponent?: React.ReactNode\r\n}\r\n\r\nexport const ProtectedRoute: React.FC<ProtectedRouteProps> = ({\r\n children,\r\n loginRoute = '/login',\r\n loadingComponent = <div>Loading...</div>\r\n}) => {\r\n const auth = useContext(AuthContext)\r\n if (!auth) throw new Error(\"AuthContext not provided\")\r\n const { user, loading } = auth\r\n const router = useRouter()\r\n const pathname = usePathname()\r\n\r\n useEffect(() => {\r\n if (!loading && !user) {\r\n router.replace(`${loginRoute}?returnUrl=${encodeURIComponent(pathname)}`)\r\n }\r\n }, [user, loading, router, pathname, loginRoute])\r\n\r\n if (loading) {\r\n return <>{loadingComponent}</>\r\n }\r\n\r\n if (!user) {\r\n return null\r\n }\r\n\r\n return <>{children}</>\r\n}\r\n","import { AuthContext } from \"../components/AuthProvider\"\r\nimport { useContext } from \"react\"\r\nimport { UserRole } from '../types'\r\n\r\nexport function useRBAC() {\r\n const auth = useContext(AuthContext)\r\n if (!auth) throw new Error(\"AuthContext not provided\")\r\n const { user } = auth\r\n \r\n const checkPermission = (permission: string): boolean => {\r\n const userRole = user?.metadata?.role as UserRole\r\n return userRole?.permissions?.includes(permission) ?? false\r\n }\r\n\r\n const hasRole = (role: string): boolean => {\r\n const userRole = user?.metadata?.role as UserRole\r\n return userRole?.role === role\r\n }\r\n\r\n return {\r\n checkPermission,\r\n hasRole\r\n }\r\n}","import { ReactNode } from 'react'\r\nimport { useRBAC } from '../../hooks/useRBAC'\r\n\r\ninterface RequirePermissionProps {\r\n permission: string\r\n children: ReactNode\r\n fallback?: ReactNode\r\n}\r\n\r\nexport function RequirePermission({ permission, children, fallback = null }: RequirePermissionProps) {\r\n const { checkPermission } = useRBAC()\r\n \r\n if (!checkPermission(permission)) {\r\n return <>{fallback}</>\r\n }\r\n \r\n return <>{children}</>\r\n}","import { createClientComponentClient } from '@supabase/auth-helpers-nextjs'\r\nimport type { Database } from './database.types'\r\n\r\nexport const createClient = () => {\r\n if (!process.env.NEXT_PUBLIC_SUPABASE_URL || !process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY) {\r\n throw new Error('Missing Supabase environment variables')\r\n }\r\n\r\n return createClientComponentClient<Database>()\r\n}\r\n\r\n// Safe supabase client that only initializes when environment variables are available\r\nlet _supabaseClient: ReturnType<typeof createClientComponentClient<Database>> | null = null;\r\n\r\nexport const getSupabaseClient = () => {\r\n if (!_supabaseClient) {\r\n _supabaseClient = createClient();\r\n }\r\n return _supabaseClient;\r\n}\r\n\r\n// Only export supabase if environment variables are available\r\n// This prevents breaking existing apps that don't use Supabase\r\nexport const supabase = (() => {\r\n try {\r\n if (process.env.NEXT_PUBLIC_SUPABASE_URL && process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY) {\r\n return createClient();\r\n }\r\n } catch (error) {\r\n // Silently fail if environment variables are not available\r\n console.warn('Supabase client not initialized: environment variables not available');\r\n }\r\n return null;\r\n})();\r\n\r\n","import { useState } from 'react'\r\nimport { supabase } from '../utils/supabase'\r\n\r\nexport function use2FA() {\r\n const [loading, setLoading] = useState(false)\r\n const [error, setError] = useState<Error | null>(null)\r\n\r\n const setup2FA = async () => {\r\n if (!supabase) {\r\n throw new Error('Supabase client not initialized. Please check your environment variables.');\r\n }\r\n\r\n setLoading(true)\r\n setError(null)\r\n \r\n try {\r\n const { data, error } = await supabase.auth.mfa.enroll({\r\n factorType: 'totp'\r\n })\r\n \r\n if (error) throw error\r\n \r\n return data\r\n } catch (err) {\r\n const error = err as Error\r\n setError(error)\r\n throw error\r\n } finally {\r\n setLoading(false)\r\n }\r\n }\r\n\r\n const verify2FA = async (factorId: string, challengeId: string, code: string) => {\r\n if (!supabase) {\r\n throw new Error('Supabase client not initialized. Please check your environment variables.');\r\n }\r\n\r\n setLoading(true)\r\n setError(null)\r\n \r\n try {\r\n const { data, error } = await supabase.auth.mfa.verify({\r\n factorId,\r\n challengeId,\r\n code\r\n })\r\n \r\n if (error) throw error\r\n \r\n return data\r\n } catch (err) {\r\n const error = err as Error\r\n setError(error)\r\n throw error\r\n } finally {\r\n setLoading(false)\r\n }\r\n }\r\n\r\n const unenroll2FA = async (factorId: string) => {\r\n if (!supabase) {\r\n throw new Error('Supabase client not initialized. Please check your environment variables.');\r\n }\r\n\r\n setLoading(true)\r\n setError(null)\r\n \r\n try {\r\n const { data, error } = await supabase.auth.mfa.unenroll({\r\n factorId\r\n })\r\n \r\n if (error) throw error\r\n \r\n return data\r\n } catch (err) {\r\n const error = err as Error\r\n setError(error)\r\n throw error\r\n } finally {\r\n setLoading(false)\r\n }\r\n }\r\n\r\n return {\r\n setup2FA,\r\n verify2FA,\r\n unenroll2FA,\r\n loading,\r\n error\r\n }\r\n}\r\n\r\n","import { useState } from 'react'\r\nimport { use2FA } from '../../hooks/use2FA'\r\n\r\nexport function TwoFactorSetup() {\r\n const { setup2FA, verify2FA, loading, error } = use2FA()\r\n const [qrCode, setQrCode] = useState<string>('')\r\n const [factorId, setFactorId] = useState<string>('')\r\n const [challengeId, setChallengeId] = useState<string>('')\r\n const [verificationCode, setVerificationCode] = useState('')\r\n const [setupComplete, setSetupComplete] = useState(false)\r\n\r\n const handleSetup = async () => {\r\n try {\r\n const data = await setup2FA()\r\n // Store the factor ID and QR code from the enrollment response\r\n setFactorId(data.id)\r\n setQrCode(data.totp.qr_code)\r\n } catch (error) {\r\n console.error('Failed to setup 2FA:', error)\r\n }\r\n }\r\n\r\n const handleVerify = async () => {\r\n if (!factorId || !verificationCode) {\r\n console.error('Missing factor ID or verification code')\r\n return\r\n }\r\n\r\n try {\r\n // For TOTP verification, we need to create a challenge first\r\n // This is a simplified version - in practice, you might need to call\r\n // a challenge endpoint first to get the challengeId\r\n const mockChallengeId = 'challenge-' + Date.now()\r\n await verify2FA(factorId, mockChallengeId, verificationCode)\r\n setSetupComplete(true)\r\n } catch (error) {\r\n console.error('Failed to verify 2FA:', error)\r\n }\r\n }\r\n\r\n return (\r\n <div className=\"space-y-4\">\r\n {!qrCode && (\r\n <button\r\n onClick={handleSetup}\r\n disabled={loading}\r\n className=\"px-4 py-2 bg-blue-500 text-white rounded disabled:opacity-50\"\r\n >\r\n {loading ? 'Setting up...' : 'Setup 2FA'}\r\n </button>\r\n )}\r\n\r\n {qrCode && !setupComplete && (\r\n <div className=\"space-y-4\">\r\n <div className=\"text-sm text-gray-600\">\r\n Scan this QR code with your authenticator app:\r\n </div>\r\n <div className=\"flex justify-center\">\r\n <img src={qrCode} alt=\"2FA QR Code\" className=\"border rounded\" />\r\n </div>\r\n <div>\r\n <input\r\n type=\"text\"\r\n value={verificationCode}\r\n onChange={(e) => setVerificationCode(e.target.value)}\r\n placeholder=\"Enter 6-digit code from your app\"\r\n className=\"w-full px-3 py-2 border rounded focus:outline-none focus:ring-2 focus:ring-blue-500\"\r\n maxLength={6}\r\n />\r\n </div>\r\n <button\r\n onClick={handleVerify}\r\n disabled={loading || !verificationCode || verificationCode.length !== 6}\r\n className=\"w-full px-4 py-2 bg-blue-500 text-white rounded disabled:opacity-50\"\r\n >\r\n {loading ? 'Verifying...' : 'Verify & Complete Setup'}\r\n </button>\r\n </div>\r\n )}\r\n\r\n {setupComplete && (\r\n <div className=\"p-4 bg-green-100 border border-green-400 text-green-700 rounded\">\r\n ✅ 2FA setup complete! Your account is now more secure.\r\n </div>\r\n )}\r\n\r\n {error && (\r\n <div className=\"p-4 bg-red-100 border border-red-400 text-red-700 rounded\">\r\n ❌ Error: {error.message}\r\n </div>\r\n )}\r\n </div>\r\n )\r\n}\r\n\r\n"]}