feat: add first name capture at signup and multi-step delete account confirmation
This commit is contained in:
1 parent
0cc08f7c26
commit
5b1124cd85
4 files changed
+233
-15
No files matched your search
+1
-1
@@ -1 +1 @@
|
||||
if(!self.define){let e,s={};const a=(a,n)=>(a=new URL(a+".js",n).href,s[a]||new Promise(s=>{if("document"in self){const e=document.createElement("script");e.src=a,e.onload=s,document.head.appendChild(e)}else e=a,importScripts(a),s()}).then(()=>{let e=s[a];if(!e)throw new Error(`Module ${a} didn’t register its module`);return e}));self.define=(n,i)=>{const c=e||("document"in self?document.currentScript.src:"")||location.href;if(s[c])return;let t={};const r=e=>a(e,c),o={module:{uri:c},exports:t,require:r};s[c]=Promise.all(n.map(e=>o[e]||r(e))).then(e=>(i(...e),t))}}define(["./workbox-4754cb34"],function(e){"use strict";importScripts(),self.skipWaiting(),e.clientsClaim(),e.precacheAndRoute([{url:"/_next/static/chunks/172-71074a5b97c03327.js",revision:"71074a5b97c03327"},{url:"/_next/static/chunks/462-718696c85490a0df.js",revision:"718696c85490a0df"},{url:"/_next/static/chunks/497-dc7d5e6b69ac9e5c.js",revision:"dc7d5e6b69ac9e5c"},{url:"/_next/static/chunks/4bd1b696-b7529f9b306ab05d.js",revision:"b7529f9b306ab05d"},{url:"/_next/static/chunks/512-8d2b9de6fda25175.js",revision:"8d2b9de6fda25175"},{url:"/_next/static/chunks/7508b87c-97d7ae290120d64a.js",revision:"97d7ae290120d64a"},{url:"/_next/static/chunks/995.a093d11da39e25d3.js",revision:"a093d11da39e25d3"},{url:"/_next/static/chunks/app/_global-error/page-2af6c391bfa86449.js",revision:"2af6c391bfa86449"},{url:"/_next/static/chunks/app/_not-found/page-f75e7ecfbcc8dd77.js",revision:"f75e7ecfbcc8dd77"},{url:"/_next/static/chunks/app/admin/page-121d83c28093566e.js",revision:"121d83c28093566e"},{url:"/_next/static/chunks/app/api/debug-smtp/route-2af6c391bfa86449.js",revision:"2af6c391bfa86449"},{url:"/_next/static/chunks/app/api/send-email/route-2af6c391bfa86449.js",revision:"2af6c391bfa86449"},{url:"/_next/static/chunks/app/api/send-scheduled-emails/route-2af6c391bfa86449.js",revision:"2af6c391bfa86449"},{url:"/_next/static/chunks/app/layout-7f3802a6a2a60f7d.js",revision:"7f3802a6a2a60f7d"},{url:"/_next/static/chunks/app/page-da425629f73a1f3a.js",revision:"da425629f73a1f3a"},{url:"/_next/static/chunks/app/profile/page-7124e76cdfa45e42.js",revision:"7124e76cdfa45e42"},{url:"/_next/static/chunks/app/testimonies/page-7fc7ddaa6cbd104f.js",revision:"7fc7ddaa6cbd104f"},{url:"/_next/static/chunks/dd8162e8-bea2cd35813297c3.js",revision:"bea2cd35813297c3"},{url:"/_next/static/chunks/framework-292291387d6b2e39.js",revision:"292291387d6b2e39"},{url:"/_next/static/chunks/main-5e55aa9a8969fd08.js",revision:"5e55aa9a8969fd08"},{url:"/_next/static/chunks/main-app-1640b70ccc992192.js",revision:"1640b70ccc992192"},{url:"/_next/static/chunks/next/dist/client/components/builtin/app-error-2af6c391bfa86449.js",revision:"2af6c391bfa86449"},{url:"/_next/static/chunks/next/dist/client/components/builtin/forbidden-2af6c391bfa86449.js",revision:"2af6c391bfa86449"},{url:"/_next/static/chunks/next/dist/client/components/builtin/global-error-647436fbb68222b8.js",revision:"647436fbb68222b8"},{url:"/_next/static/chunks/next/dist/client/components/builtin/not-found-2af6c391bfa86449.js",revision:"2af6c391bfa86449"},{url:"/_next/static/chunks/next/dist/client/components/builtin/unauthorized-2af6c391bfa86449.js",revision:"2af6c391bfa86449"},{url:"/_next/static/chunks/polyfills-42372ed130431b0a.js",revision:"846118c33b2c0e922d7b3a7676f81f6f"},{url:"/_next/static/chunks/webpack-6b6a51bcb4cc4744.js",revision:"6b6a51bcb4cc4744"},{url:"/_next/static/css/ec0e59c59f332d11.css",revision:"ec0e59c59f332d11"},{url:"/_next/static/media/4cf2300e9c8272f7-s.p.woff2",revision:"18bae71b1e1b2bb25321090a3b563103"},{url:"/_next/static/media/747892c23ea88013-s.woff2",revision:"a0761690ccf4441ace5cec893b82d4ab"},{url:"/_next/static/media/8d697b304b401681-s.woff2",revision:"cc728f6c0adb04da0dfcb0fc436a8ae5"},{url:"/_next/static/media/93f479601ee12b01-s.p.woff2",revision:"da83d5f06d825c5ae65b7cca706cb312"},{url:"/_next/static/media/9610d9e46709d722-s.woff2",revision:"7b7c0ef93df188a852344fc272fc096b"},{url:"/_next/static/media/ba015fad6dcf6784-s.woff2",revision:"8ea4f719af3312a055caf09f34c89a77"},{url:"/_next/static/zGoUFgd26mjX9VCibjeQJ/_buildManifest.js",revision:"44608b7d53e1eefcd54452c125d6300e"},{url:"/_next/static/zGoUFgd26mjX9VCibjeQJ/_ssgManifest.js",revision:"b6652df95db52feb4daf4eca35380933"},{url:"/file.svg",revision:"d09f95206c3fa0bb9bd9fefabfd0ea71"},{url:"/firebase-messaging-sw.js",revision:"396ffcf00a63da03dfc03d78d4815494"},{url:"/globe.svg",revision:"2aaafa6a49b6563925fe440891e32717"},{url:"/icon-192x192.png",revision:"bbbd7efc0e31088ae0a3aeede7608534"},{url:"/icon-512x512.png",revision:"400538d76556a3a8ee4fd3dfda7bc092"},{url:"/locales/en/common.json",revision:"41332abbb11f0b33b3eb308a5448f8d6"},{url:"/manifest.json",revision:"928e96ccc236cff27f97d358c0517c73"},{url:"/next.svg",revision:"8e061864f388b47f33a1c3780831193e"},{url:"/vercel.svg",revision:"c0af2f507b369b085b35ef4bbe3bcf1e"},{url:"/window.svg",revision:"a2760511c65806022ad20adf74370ff3"}],{ignoreURLParametersMatching:[]}),e.cleanupOutdatedCaLine truncated
|
||||
if(!self.define){let e,s={};const a=(a,n)=>(a=new URL(a+".js",n).href,s[a]||new Promise(s=>{if("document"in self){const e=document.createElement("script");e.src=a,e.onload=s,document.head.appendChild(e)}else e=a,importScripts(a),s()}).then(()=>{let e=s[a];if(!e)throw new Error(`Module ${a} didn’t register its module`);return e}));self.define=(n,i)=>{const t=e||("document"in self?document.currentScript.src:"")||location.href;if(s[t])return;let c={};const r=e=>a(e,t),o={module:{uri:t},exports:c,require:r};s[t]=Promise.all(n.map(e=>o[e]||r(e))).then(e=>(i(...e),c))}}define(["./workbox-4754cb34"],function(e){"use strict";importScripts(),self.skipWaiting(),e.clientsClaim(),e.precacheAndRoute([{url:"/_next/static/chunks/172-71074a5b97c03327.js",revision:"71074a5b97c03327"},{url:"/_next/static/chunks/462-a82df50800682a1f.js",revision:"a82df50800682a1f"},{url:"/_next/static/chunks/497-aef161184cee56bd.js",revision:"aef161184cee56bd"},{url:"/_next/static/chunks/4bd1b696-b7529f9b306ab05d.js",revision:"b7529f9b306ab05d"},{url:"/_next/static/chunks/512-8d2b9de6fda25175.js",revision:"8d2b9de6fda25175"},{url:"/_next/static/chunks/7508b87c-97d7ae290120d64a.js",revision:"97d7ae290120d64a"},{url:"/_next/static/chunks/995.a093d11da39e25d3.js",revision:"a093d11da39e25d3"},{url:"/_next/static/chunks/app/_global-error/page-2af6c391bfa86449.js",revision:"2af6c391bfa86449"},{url:"/_next/static/chunks/app/_not-found/page-f75e7ecfbcc8dd77.js",revision:"f75e7ecfbcc8dd77"},{url:"/_next/static/chunks/app/admin/page-43db0261b52e6ad1.js",revision:"43db0261b52e6ad1"},{url:"/_next/static/chunks/app/api/debug-smtp/route-2af6c391bfa86449.js",revision:"2af6c391bfa86449"},{url:"/_next/static/chunks/app/api/send-email/route-2af6c391bfa86449.js",revision:"2af6c391bfa86449"},{url:"/_next/static/chunks/app/api/send-scheduled-emails/route-2af6c391bfa86449.js",revision:"2af6c391bfa86449"},{url:"/_next/static/chunks/app/layout-7f3802a6a2a60f7d.js",revision:"7f3802a6a2a60f7d"},{url:"/_next/static/chunks/app/page-ec10f63ea1344f19.js",revision:"ec10f63ea1344f19"},{url:"/_next/static/chunks/app/profile/page-c20b439f2da997d0.js",revision:"c20b439f2da997d0"},{url:"/_next/static/chunks/app/testimonies/page-667b462e3833ac5f.js",revision:"667b462e3833ac5f"},{url:"/_next/static/chunks/dd8162e8-d831a49a8bccd99c.js",revision:"d831a49a8bccd99c"},{url:"/_next/static/chunks/framework-292291387d6b2e39.js",revision:"292291387d6b2e39"},{url:"/_next/static/chunks/main-5e55aa9a8969fd08.js",revision:"5e55aa9a8969fd08"},{url:"/_next/static/chunks/main-app-1640b70ccc992192.js",revision:"1640b70ccc992192"},{url:"/_next/static/chunks/next/dist/client/components/builtin/app-error-2af6c391bfa86449.js",revision:"2af6c391bfa86449"},{url:"/_next/static/chunks/next/dist/client/components/builtin/forbidden-2af6c391bfa86449.js",revision:"2af6c391bfa86449"},{url:"/_next/static/chunks/next/dist/client/components/builtin/global-error-647436fbb68222b8.js",revision:"647436fbb68222b8"},{url:"/_next/static/chunks/next/dist/client/components/builtin/not-found-2af6c391bfa86449.js",revision:"2af6c391bfa86449"},{url:"/_next/static/chunks/next/dist/client/components/builtin/unauthorized-2af6c391bfa86449.js",revision:"2af6c391bfa86449"},{url:"/_next/static/chunks/polyfills-42372ed130431b0a.js",revision:"846118c33b2c0e922d7b3a7676f81f6f"},{url:"/_next/static/chunks/webpack-6b6a51bcb4cc4744.js",revision:"6b6a51bcb4cc4744"},{url:"/_next/static/css/fa953c5a9633cd12.css",revision:"fa953c5a9633cd12"},{url:"/_next/static/media/4cf2300e9c8272f7-s.p.woff2",revision:"18bae71b1e1b2bb25321090a3b563103"},{url:"/_next/static/media/747892c23ea88013-s.woff2",revision:"a0761690ccf4441ace5cec893b82d4ab"},{url:"/_next/static/media/8d697b304b401681-s.woff2",revision:"cc728f6c0adb04da0dfcb0fc436a8ae5"},{url:"/_next/static/media/93f479601ee12b01-s.p.woff2",revision:"da83d5f06d825c5ae65b7cca706cb312"},{url:"/_next/static/media/9610d9e46709d722-s.woff2",revision:"7b7c0ef93df188a852344fc272fc096b"},{url:"/_next/static/media/ba015fad6dcf6784-s.woff2",revision:"8ea4f719af3312a055caf09f34c89a77"},{url:"/_next/static/vQh3rsBwXC6jIslNKb19G/_buildManifest.js",revision:"44608b7d53e1eefcd54452c125d6300e"},{url:"/_next/static/vQh3rsBwXC6jIslNKb19G/_ssgManifest.js",revision:"b6652df95db52feb4daf4eca35380933"},{url:"/file.svg",revision:"d09f95206c3fa0bb9bd9fefabfd0ea71"},{url:"/firebase-messaging-sw.js",revision:"396ffcf00a63da03dfc03d78d4815494"},{url:"/globe.svg",revision:"2aaafa6a49b6563925fe440891e32717"},{url:"/icon-192x192.png",revision:"bbbd7efc0e31088ae0a3aeede7608534"},{url:"/icon-512x512.png",revision:"400538d76556a3a8ee4fd3dfda7bc092"},{url:"/locales/en/common.json",revision:"41332abbb11f0b33b3eb308a5448f8d6"},{url:"/manifest.json",revision:"6dbf565091414e98afd54d79577bb36d"},{url:"/next.svg",revision:"8e061864f388b47f33a1c3780831193e"},{url:"/vercel.svg",revision:"c0af2f507b369b085b35ef4bbe3bcf1e"},{url:"/window.svg",revision:"a2760511c65806022ad20adf74370ff3"}],{ignoreURLParametersMatching:[]}),e.cleanupOutdatedCaLine truncated
|
||||
@@ -8,8 +8,14 @@ interface AboutPageProps {
|
||||
}
|
||||
|
||||
export default function AboutPage({ userEmail }: AboutPageProps) {
|
||||
const { logout } = useAuth();
|
||||
const [showConfirm, setShowConfirm] = useState(false);
|
||||
const { logout, deleteAccount } = useAuth();
|
||||
const [showLogoutConfirm, setShowLogoutConfirm] = useState(false);
|
||||
const [showDeleteDialog, setShowDeleteDialog] = useState(false);
|
||||
const [deleteStep, setDeleteStep] = useState(0); // 0=initial, 1=first confirm, 2=second confirm, 3=type DELETE, 4=type email
|
||||
const [deleteConfirmText, setDeleteConfirmText] = useState('');
|
||||
const [deleteEmail, setDeleteEmail] = useState('');
|
||||
const [deleteLoading, setDeleteLoading] = useState(false);
|
||||
const [deleteError, setDeleteError] = useState('');
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gradient-to-b from-slate-900 to-slate-800 p-4 pb-32 pt-8">
|
||||
@@ -63,26 +69,38 @@ export default function AboutPage({ userEmail }: AboutPageProps) {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Logout Section */}
|
||||
<div>
|
||||
{/* Logout and Delete Section */}
|
||||
<div className="space-y-3">
|
||||
<button
|
||||
onClick={() => setShowConfirm(true)}
|
||||
onClick={() => setShowLogoutConfirm(true)}
|
||||
className="w-full px-4 py-3 bg-red-600 hover:bg-red-700 text-white font-medium rounded-lg transition-colors"
|
||||
>
|
||||
Logout
|
||||
</button>
|
||||
<button
|
||||
onClick={() => {
|
||||
setShowDeleteDialog(true);
|
||||
setDeleteStep(0);
|
||||
setDeleteConfirmText('');
|
||||
setDeleteEmail('');
|
||||
setDeleteError('');
|
||||
}}
|
||||
className="w-full px-4 py-3 bg-red-900 hover:bg-red-800 text-red-200 font-medium rounded-lg transition-colors border border-red-700"
|
||||
>
|
||||
Delete Account
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Logout Confirmation Modal */}
|
||||
{showConfirm && (
|
||||
{showLogoutConfirm && (
|
||||
<div className="fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4">
|
||||
<div className="bg-slate-800 rounded-xl p-6 max-w-sm w-full">
|
||||
<h2 className="text-xl font-bold text-white mb-2">Logout?</h2>
|
||||
<p className="text-slate-400 mb-6">Are you sure you want to logout?</p>
|
||||
<div className="flex gap-3">
|
||||
<button
|
||||
onClick={() => setShowConfirm(false)}
|
||||
onClick={() => setShowLogoutConfirm(false)}
|
||||
className="flex-1 px-4 py-2 rounded-lg bg-slate-700 text-white font-medium hover:bg-slate-600 transition-colors"
|
||||
>
|
||||
Cancel
|
||||
@@ -97,6 +115,161 @@ export default function AboutPage({ userEmail }: AboutPageProps) {
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Delete Account Multi-Step Modal */}
|
||||
{showDeleteDialog && (
|
||||
<div className="fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4">
|
||||
<div className="bg-slate-800 rounded-xl p-6 max-w-sm w-full">
|
||||
{deleteStep === 0 && (
|
||||
<>
|
||||
<h2 className="text-xl font-bold text-red-400 mb-2">⚠️ Delete Account?</h2>
|
||||
<p className="text-slate-300 mb-2 font-semibold">This action cannot be undone.</p>
|
||||
<p className="text-slate-400 mb-6 text-sm">All your prayers, reflections, and account data will be permanently deleted.</p>
|
||||
<div className="flex gap-3">
|
||||
<button
|
||||
onClick={() => setShowDeleteDialog(false)}
|
||||
className="flex-1 px-4 py-2 rounded-lg bg-slate-700 text-white font-medium hover:bg-slate-600 transition-colors"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setDeleteStep(1)}
|
||||
className="flex-1 px-4 py-2 rounded-lg bg-red-600 text-white font-medium hover:bg-red-700 transition-colors"
|
||||
>
|
||||
Continue
|
||||
</button>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{deleteStep === 1 && (
|
||||
<>
|
||||
<h2 className="text-xl font-bold text-red-400 mb-2">Are you absolutely sure?</h2>
|
||||
<p className="text-slate-400 mb-6">You will lose all your prayers and data. This is permanent.</p>
|
||||
<div className="flex gap-3">
|
||||
<button
|
||||
onClick={() => setDeleteStep(0)}
|
||||
className="flex-1 px-4 py-2 rounded-lg bg-slate-700 text-white font-medium hover:bg-slate-600 transition-colors"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setDeleteStep(2)}
|
||||
className="flex-1 px-4 py-2 rounded-lg bg-red-600 text-white font-medium hover:bg-red-700 transition-colors"
|
||||
>
|
||||
I'm Sure
|
||||
</button>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{deleteStep === 2 && (
|
||||
<>
|
||||
<h2 className="text-xl font-bold text-red-400 mb-2">Type DELETE to confirm</h2>
|
||||
<p className="text-slate-400 mb-4">Enter the word "DELETE" to proceed:</p>
|
||||
<input
|
||||
type="text"
|
||||
value={deleteConfirmText}
|
||||
onChange={(e) => setDeleteConfirmText(e.target.value.toUpperCase())}
|
||||
placeholder="Type DELETE"
|
||||
className="w-full p-2 bg-slate-700 border border-slate-600 rounded-lg text-white placeholder-slate-500 mb-4 focus:ring-2 focus:ring-red-500 focus:border-transparent"
|
||||
/>
|
||||
<div className="flex gap-3">
|
||||
<button
|
||||
onClick={() => setDeleteStep(1)}
|
||||
className="flex-1 px-4 py-2 rounded-lg bg-slate-700 text-white font-medium hover:bg-slate-600 transition-colors"
|
||||
>
|
||||
Back
|
||||
</button>
|
||||
<button
|
||||
onClick={() => deleteConfirmText === 'DELETE' ? setDeleteStep(3) : setDeleteError('Please type DELETE exactly')}
|
||||
disabled={deleteConfirmText !== 'DELETE'}
|
||||
className="flex-1 px-4 py-2 rounded-lg bg-red-600 text-white font-medium hover:bg-red-700 disabled:bg-red-900 disabled:cursor-not-allowed transition-colors"
|
||||
>
|
||||
Continue
|
||||
</button>
|
||||
</div>
|
||||
{deleteError && <p className="text-red-400 text-sm mt-2">{deleteError}</p>}
|
||||
</>
|
||||
)}
|
||||
|
||||
{deleteStep === 3 && (
|
||||
<>
|
||||
<h2 className="text-xl font-bold text-red-400 mb-2">Confirm your email</h2>
|
||||
<p className="text-slate-400 mb-4">Enter your email to verify:</p>
|
||||
<input
|
||||
type="email"
|
||||
value={deleteEmail}
|
||||
onChange={(e) => setDeleteEmail(e.target.value)}
|
||||
placeholder="Enter your email"
|
||||
className="w-full p-2 bg-slate-700 border border-slate-600 rounded-lg text-white placeholder-slate-500 mb-4 focus:ring-2 focus:ring-red-500 focus:border-transparent"
|
||||
/>
|
||||
<div className="flex gap-3">
|
||||
<button
|
||||
onClick={() => setDeleteStep(2)}
|
||||
className="flex-1 px-4 py-2 rounded-lg bg-slate-700 text-white font-medium hover:bg-slate-600 transition-colors"
|
||||
>
|
||||
Back
|
||||
</button>
|
||||
<button
|
||||
onClick={() => deleteEmail === userEmail ? setDeleteStep(4) : setDeleteError('Email does not match')}
|
||||
disabled={!deleteEmail}
|
||||
className="flex-1 px-4 py-2 rounded-lg bg-red-600 text-white font-medium hover:bg-red-700 disabled:bg-red-900 disabled:cursor-not-allowed transition-colors"
|
||||
>
|
||||
Continue
|
||||
</button>
|
||||
</div>
|
||||
{deleteError && <p className="text-red-400 text-sm mt-2">{deleteError}</p>}
|
||||
</>
|
||||
)}
|
||||
|
||||
{deleteStep === 4 && (
|
||||
<>
|
||||
<h2 className="text-xl font-bold text-red-400 mb-2">Final confirmation</h2>
|
||||
<p className="text-slate-400 mb-4">Check this box to confirm you understand your account will be permanently deleted:</p>
|
||||
<div className="bg-slate-700 p-3 rounded-lg mb-4">
|
||||
<label className="flex items-center gap-3 cursor-pointer">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={deleteConfirmText === 'CONFIRM'}
|
||||
onChange={(e) => setDeleteConfirmText(e.target.checked ? 'CONFIRM' : '')}
|
||||
className="w-5 h-5 rounded border-slate-600 bg-slate-600 text-red-600 focus:ring-2 focus:ring-red-500 cursor-pointer"
|
||||
/>
|
||||
<span className="text-slate-300 text-sm">
|
||||
I understand this is permanent and cannot be undone
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
<div className="flex gap-3">
|
||||
<button
|
||||
onClick={() => setDeleteStep(3)}
|
||||
className="flex-1 px-4 py-2 rounded-lg bg-slate-700 text-white font-medium hover:bg-slate-600 transition-colors"
|
||||
>
|
||||
Back
|
||||
</button>
|
||||
<button
|
||||
onClick={async () => {
|
||||
setDeleteLoading(true);
|
||||
setDeleteError('');
|
||||
try {
|
||||
await deleteAccount();
|
||||
} catch (err: unknown) {
|
||||
setDeleteError(err instanceof Error ? err.message : 'Failed to delete account');
|
||||
setDeleteLoading(false);
|
||||
}
|
||||
}}
|
||||
disabled={deleteConfirmText !== 'CONFIRM' || deleteLoading}
|
||||
className="flex-1 px-4 py-2 rounded-lg bg-red-700 text-white font-bold hover:bg-red-800 disabled:bg-red-900 disabled:cursor-not-allowed transition-colors"
|
||||
>
|
||||
{deleteLoading ? 'Deleting...' : 'Delete Account'}
|
||||
</button>
|
||||
</div>
|
||||
{deleteError && <p className="text-red-400 text-sm mt-2">{deleteError}</p>}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -7,6 +7,7 @@ export default function Login() {
|
||||
const [email, setEmail] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const [confirmPassword, setConfirmPassword] = useState('');
|
||||
const [firstName, setFirstName] = useState('');
|
||||
const [isSignup, setIsSignup] = useState(false);
|
||||
const [rememberMe, setRememberMe] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
@@ -19,13 +20,18 @@ export default function Login() {
|
||||
setLoading(true);
|
||||
|
||||
if (isSignup) {
|
||||
if (!firstName.trim()) {
|
||||
setError('Please enter your first name');
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
if (password !== confirmPassword) {
|
||||
setError('Passwords do not match');
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await signup(email, password);
|
||||
await signup(email, password, firstName);
|
||||
} catch (err: unknown) {
|
||||
setError(err instanceof Error ? err.message : 'An error occurred');
|
||||
}
|
||||
@@ -61,6 +67,19 @@ export default function Login() {
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
{isSignup && (
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-300 mb-2">First Name</label>
|
||||
<input
|
||||
type="text"
|
||||
value={firstName}
|
||||
onChange={(e) => setFirstName(e.target.value)}
|
||||
className="w-full p-3 bg-gray-700 border border-gray-600 rounded-lg text-white placeholder-gray-400 focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-colors"
|
||||
placeholder="Enter your first name"
|
||||
required={isSignup}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-300 mb-2">Email</label>
|
||||
<input
|
||||
@@ -135,6 +154,7 @@ export default function Login() {
|
||||
setIsSignup(!isSignup);
|
||||
setError('');
|
||||
setConfirmPassword('');
|
||||
setFirstName('');
|
||||
}}
|
||||
className="text-blue-400 hover:text-blue-300 transition-colors"
|
||||
>
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
'use client';
|
||||
|
||||
import { createContext, useContext, useEffect, useState, ReactNode } from 'react';
|
||||
import { User, signInWithEmailAndPassword, signOut, onAuthStateChanged, createUserWithEmailAndPassword } from 'firebase/auth';
|
||||
import { User, signInWithEmailAndPassword, signOut, onAuthStateChanged, createUserWithEmailAndPassword, updateProfile, deleteUser } from 'firebase/auth';
|
||||
import { auth, db, app } from '@/lib/firebase';
|
||||
import { doc, setDoc } from 'firebase/firestore';
|
||||
import { doc, setDoc, query, where, collection, getDocs, deleteDoc } from 'firebase/firestore';
|
||||
|
||||
interface AuthContextType {
|
||||
user: User | null;
|
||||
login: (email: string, password: string) => Promise<void>;
|
||||
signup: (email: string, password: string) => Promise<void>;
|
||||
signup: (email: string, password: string, firstName?: string) => Promise<void>;
|
||||
logout: () => Promise<void>;
|
||||
deleteAccount: () => Promise<void>;
|
||||
loading: boolean;
|
||||
isAdmin: boolean;
|
||||
}
|
||||
@@ -72,8 +73,11 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
await signInWithEmailAndPassword(auth, email, password);
|
||||
};
|
||||
|
||||
const signup = async (email: string, password: string) => {
|
||||
await createUserWithEmailAndPassword(auth, email, password);
|
||||
const signup = async (email: string, password: string, firstName?: string) => {
|
||||
const userCredential = await createUserWithEmailAndPassword(auth, email, password);
|
||||
if (firstName) {
|
||||
await updateProfile(userCredential.user, { displayName: firstName });
|
||||
}
|
||||
};
|
||||
|
||||
const logout = async () => {
|
||||
@@ -81,8 +85,29 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
await signOut(auth);
|
||||
};
|
||||
|
||||
const deleteAccount = async () => {
|
||||
if (!user) throw new Error('No user logged in');
|
||||
|
||||
// Delete all prayers from Firestore
|
||||
const prayersQuery = query(collection(db, 'prayers'), where('userId', '==', user.uid));
|
||||
const prayersSnapshot = await getDocs(prayersQuery);
|
||||
for (const prayerDoc of prayersSnapshot.docs) {
|
||||
await deleteDoc(prayerDoc.ref);
|
||||
}
|
||||
|
||||
// Delete user document if it exists
|
||||
const userDocRef = doc(db, 'users', user.uid);
|
||||
await deleteDoc(userDocRef).catch(() => {
|
||||
// User doc might not exist, that's okay
|
||||
});
|
||||
|
||||
// Delete Firebase Auth user
|
||||
await deleteUser(user);
|
||||
localStorage.removeItem('rememberMeTimestamp');
|
||||
};
|
||||
|
||||
return (
|
||||
<AuthContext.Provider value={{ user, login, signup, logout, loading, isAdmin }}>
|
||||
<AuthContext.Provider value={{ user, login, signup, logout, deleteAccount, loading, isAdmin }}>
|
||||
{children}
|
||||
</AuthContext.Provider>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user