fix: prevent Firestore access for unverified users and add password prompt for resend
This commit is contained in:
1 parent
81beeeee70
commit
90adc2eb32
3 files changed
+31
-4
No files matched your search
+1
-1
@@ -44,7 +44,7 @@ export default function Home() {
|
||||
|
||||
// Load prayers from Firestore
|
||||
useEffect(() => {
|
||||
if (!user) return;
|
||||
if (!user || !user.emailVerified) return;
|
||||
|
||||
const loadPrayers = async () => {
|
||||
try {
|
||||
|
||||
@@ -20,6 +20,8 @@ export default function Login() {
|
||||
const [verificationSent, setVerificationSent] = useState(false);
|
||||
const [needsVerification, setNeedsVerification] = useState(false);
|
||||
const [resendEmail, setResendEmail] = useState('');
|
||||
const [resendPassword, setResendPassword] = useState('');
|
||||
const [showPasswordPrompt, setShowPasswordPrompt] = useState(false);
|
||||
const { login, signup, sendPasswordReset, sendVerificationEmailToUser } = useAuth();
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
@@ -83,13 +85,18 @@ export default function Login() {
|
||||
};
|
||||
|
||||
const handleResendVerification = async () => {
|
||||
if (!resendPassword) {
|
||||
setShowPasswordPrompt(true);
|
||||
return;
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
setError('');
|
||||
try {
|
||||
// Try to login temporarily to send verification
|
||||
const { signInWithEmailAndPassword } = await import('firebase/auth');
|
||||
const { auth } = await import('@/lib/firebase');
|
||||
const userCred = await signInWithEmailAndPassword(auth, resendEmail, password);
|
||||
const userCred = await signInWithEmailAndPassword(auth, resendEmail, resendPassword);
|
||||
await sendVerificationEmailToUser(userCred.user);
|
||||
|
||||
// Sign them back out
|
||||
@@ -100,8 +107,11 @@ export default function Login() {
|
||||
setNeedsVerification(false);
|
||||
setShowVerificationBanner(true);
|
||||
setVerificationSent(true);
|
||||
setResendPassword('');
|
||||
setShowPasswordPrompt(false);
|
||||
} catch (err: unknown) {
|
||||
setError(err instanceof Error ? err.message : 'Failed to resend verification email');
|
||||
setError(err instanceof Error ? err.message : 'Failed to resend verification email. Check your password.');
|
||||
setResendPassword('');
|
||||
}
|
||||
setLoading(false);
|
||||
};
|
||||
@@ -152,6 +162,23 @@ export default function Login() {
|
||||
<p className="font-semibold mb-1">📧 Can't find the email?</p>
|
||||
<p className="text-yellow-300 text-xs">Click the button below to send a new verification email.</p>
|
||||
</div>
|
||||
{showPasswordPrompt && (
|
||||
<div className="mb-3">
|
||||
<label className="block text-sm font-medium text-yellow-300 mb-2">Enter your password to resend:</label>
|
||||
<input
|
||||
type="password"
|
||||
value={resendPassword}
|
||||
onChange={(e) => setResendPassword(e.target.value)}
|
||||
placeholder="Your password"
|
||||
className="w-full p-2 bg-yellow-950 border border-yellow-700 rounded-lg text-white placeholder-yellow-600 focus:ring-2 focus:ring-yellow-500 focus:border-transparent"
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter') {
|
||||
handleResendVerification();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleResendVerification}
|
||||
|
||||
Reference in new issue
Block a user