import React, { useState, useEffect, useRef } from 'react'; import { BarChart, Bar, XAxis, YAxis, Tooltip, ResponsiveContainer } from 'recharts'; import { initLocalEngine, routeInference } from '../utils/inferenceRouter'; import HCaptcha from '@hcaptcha/react-hcaptcha'; import { supabase, useAuth, GATEWAY_URL, LEMON_CHECKOUT_URL } from '../context'; export default function AuthPage() { const { signIn, signUp } = useAuth() const [authMode, setAuthMode] = useState('login') // 'login' | 'signup' | 'forgot' const [email, setEmail] = useState('') const [password, setPassword] = useState('') const [error, setError] = useState('') const [success, setSuccess] = useState('') const captchaRef = useRef(null) const [captchaToken, setCaptchaToken] = useState(null) useEffect(() => { const handlePasswordReset = async () => { const hashParams = new URLSearchParams( window.location.hash.substring(1) ); const accessToken = hashParams.get('access_token'); const type = hashParams.get('type'); if (type === 'recovery' && accessToken) { const newPassword = prompt( 'Enter your new password (min 8 characters):' ); if (!newPassword || newPassword.length < 8) { alert('Password must be at least 8 characters'); return; } const { error } = await supabase.auth.updateUser({ password: newPassword }); if (error) { alert('Error resetting password: ' + error.message); } else { alert('Password updated successfully! Please log in.'); window.location.hash = ''; } } }; handlePasswordReset(); }, []); const handleForgotPasswordSubmit = async (e) => { e.preventDefault(); if (!email) { setError('Please enter your email address'); return; } if (!captchaToken) { setError('Please complete the captcha verification.'); return; } try { const { error } = await supabase.auth.resetPasswordForEmail( email, { redirectTo: 'https://dashboard.opticparse.com/reset-password', captchaToken: captchaToken } ); if (error) throw error; setSuccess('Password reset email sent! Check your inbox.'); captchaRef.current?.resetCaptcha(); } catch (err) { setError('Error: ' + err.message); } }; const handleGoogleSignIn = async () => { const { error } = await supabase.auth.signInWithOAuth({ provider: 'google', options: { redirectTo: 'https://dashboard.opticparse.com' } }); if (error) alert('Google sign in error: ' + error.message); }; const handleGitHubSignIn = async () => { const { error } = await supabase.auth.signInWithOAuth({ provider: 'github', options: { redirectTo: 'https://dashboard.opticparse.com' } }); if (error) alert('GitHub sign in error: ' + error.message); }; const handleSubmit = async (e) => { e.preventDefault() setError('') setSuccess('') try { if (authMode === 'login') { await signIn(email, password) } else if (authMode === 'signup') { if (!captchaToken) { setError('Please complete the captcha verification.'); return; } const { data, error: err } = await supabase.auth.signUp({ email, password, options: { captchaToken: captchaToken } }); if (err) throw err; setSuccess('Account created! Check your email to confirm.') captchaRef.current?.resetCaptcha(); } } catch (err) { setError(err.message) } } return (
← Back to Website

OpticParse & PhishVision

{authMode === 'forgot' ? 'Reset your password' : (authMode === 'login' ? 'Sign in to your developer dashboard' : 'Create your developer account')}

{authMode !== 'forgot' && ( <> )} {authMode !== 'forgot' && (
or continue with email
)} {error &&
{error}
} {success &&
{success}
}
setEmail(e.target.value)} placeholder="you@company.com" required />
{authMode !== 'forgot' && (
setPassword(e.target.value)} placeholder="••••••••" required minLength={6} /> {authMode === 'login' && ( )}
)} {authMode !== 'login' && (
setCaptchaToken(token)} onExpire={() => setCaptchaToken(null)} ref={captchaRef} theme="dark" />
)}
{authMode === 'login' ? "Don't have an account? " : (authMode === 'signup' ? 'Already have an account? ' : '')} {authMode === 'login' && { setAuthMode('signup'); setError(''); setSuccess('') }}>Sign up} {authMode === 'signup' && { setAuthMode('login'); setError(''); setSuccess('') }}>Sign in} {authMode === 'forgot' && { setAuthMode('login'); setError(''); setSuccess('') }}>Back to Login}
) }