Compare commits

...

2 Commits

Author SHA1 Message Date
KS Jannette
6b07d51cb1 add email verification step to new user onboarding flow 2026-05-11 22:13:53 -04:00
S Jannette
3c282c589c Merge pull request #35 from kjannette/config-updates
config updates
2026-05-11 16:29:57 -04:00
3 changed files with 116 additions and 12 deletions

View File

@@ -4,6 +4,7 @@ import {
signInWithEmailAndPassword, signInWithEmailAndPassword,
createUserWithEmailAndPassword, createUserWithEmailAndPassword,
signOut, signOut,
sendEmailVerification as firebaseSendEmailVerification,
} from "firebase/auth"; } from "firebase/auth";
import { auth } from "../firebase/config"; import { auth } from "../firebase/config";
import { getAccount } from "../api/account"; import { getAccount } from "../api/account";
@@ -68,6 +69,19 @@ export function AuthProvider({ children }) {
await signOut(auth); await signOut(auth);
} }
async function sendEmailVerification() {
if (auth.currentUser) {
await firebaseSendEmailVerification(auth.currentUser);
}
}
async function reloadUser() {
if (auth.currentUser) {
await auth.currentUser.reload();
setCurrentUser({ ...auth.currentUser });
}
}
const value = { const value = {
currentUser, currentUser,
userTier, userTier,
@@ -77,6 +91,8 @@ export function AuthProvider({ children }) {
signup, signup,
login, login,
logout, logout,
sendEmailVerification,
reloadUser,
refreshAccount: fetchAccount, refreshAccount: fetchAccount,
}; };

View File

@@ -128,6 +128,23 @@
font-size: 0.9rem; font-size: 0.9rem;
} }
.subscribe__subtitle strong {
color: var(--color-primary);
}
/* Verify email actions */
.subscribe__verify-actions {
text-align: center;
margin-top: 1rem;
}
.subscribe__verify-sent {
color: var(--color-success, #22c55e);
text-align: center;
font-size: 0.9rem;
margin-bottom: 0.5rem;
}
/* Subscribe card (Step 2 tier cards) */ /* Subscribe card (Step 2 tier cards) */
.subscribe-card { .subscribe-card {
background-color: var(--color-bg-card, #1a1a2e); background-color: var(--color-bg-card, #1a1a2e);

View File

@@ -10,12 +10,12 @@ import Button from "../../components/Button";
import TierPicker from "../../components/TierPicker"; import TierPicker from "../../components/TierPicker";
import "./Subscribe.css"; import "./Subscribe.css";
const STEPS = ["Create Account", "Choose Plan"]; const STEPS = ["Create Account", "Verify Email", "Choose Plan"];
export default function Subscribe() { export default function Subscribe() {
const navigate = useNavigate(); const navigate = useNavigate();
const [searchParams] = useSearchParams(); const [searchParams] = useSearchParams();
const { currentUser, signup, refreshAccount } = useAuth(); const { currentUser, signup, sendEmailVerification, reloadUser, refreshAccount } = useAuth();
const queryParameters = new URLSearchParams(window.location.search) const queryParameters = new URLSearchParams(window.location.search)
const success = queryParameters?.get("payment") const success = queryParameters?.get("payment")
@@ -30,7 +30,10 @@ export default function Subscribe() {
setTimeout(forward, 2000, success, session_id); setTimeout(forward, 2000, success, session_id);
const [step, setStep] = useState(currentUser ? 2 : 1); const [step, setStep] = useState(
currentUser ? (currentUser.emailVerified ? 3 : 2) : 1
);
const [verificationSent, setVerificationSent] = useState(false);
const [data, setData] = useState({ const [data, setData] = useState({
email: currentUser?.email || "", email: currentUser?.email || "",
password: "", password: "",
@@ -65,6 +68,8 @@ export default function Subscribe() {
setLoading(true); setLoading(true);
try { try {
await signup(data.email, data.password); await signup(data.email, data.password);
await sendEmailVerification();
setVerificationSent(true);
setStep(2); setStep(2);
} catch (err) { } catch (err) {
setError(err.message || "Failed to create account"); setError(err.message || "Failed to create account");
@@ -74,6 +79,44 @@ export default function Subscribe() {
} }
async function handleStep2() { async function handleStep2() {
setError("");
setLoading(true);
try {
await reloadUser();
const { currentUser: user } = await import("../../firebase/config").then(
(m) => ({ currentUser: m.auth.currentUser })
);
if (user?.emailVerified) {
setStep(3);
} else {
setError("Email not yet verified. Please check your inbox and click the verification link.");
}
} catch (err) {
setError(err.message || "Failed to check verification status");
} finally {
setLoading(false);
}
}
async function handleResendVerification() {
setError("");
setLoading(true);
try {
await sendEmailVerification();
setVerificationSent(true);
setError("");
} catch (err) {
if (err.code === "auth/too-many-requests") {
setError("Too many requests. Please wait a moment before trying again.");
} else {
setError(err.message || "Failed to resend verification email");
}
} finally {
setLoading(false);
}
}
async function handleStep3() {
setError(""); setError("");
if (!data.selectedTier) { if (!data.selectedTier) {
setError("Please select a plan"); setError("Please select a plan");
@@ -173,6 +216,30 @@ export default function Subscribe() {
); );
} }
function StepVerifyEmail() {
return (
<>
<h2 className="mb-sm">Verify your email</h2>
<p className="subscribe__subtitle">
We've sent a verification link to <strong>{currentUser?.email}</strong>.
Please check your inbox and click the link to verify your email address.
</p>
{verificationSent && !error && (
<p className="subscribe__verify-sent">Verification email sent!</p>
)}
<div className="subscribe__verify-actions">
<Button
onClick={handleResendVerification}
disabled={loading}
variant="ghost"
>
{loading ? "Sending..." : "Resend verification email"}
</Button>
</div>
</>
);
}
function StepChoosePlan() { function StepChoosePlan() {
return ( return (
<> <>
@@ -194,6 +261,7 @@ export default function Subscribe() {
async function handleNext() { async function handleNext() {
if (step === 1) handleStep1(); if (step === 1) handleStep1();
else if (step === 2) await handleStep2(); else if (step === 2) await handleStep2();
else if (step === 3) await handleStep3();
} }
function handleBack() { function handleBack() {
@@ -204,16 +272,18 @@ export default function Subscribe() {
const nextLabel = const nextLabel =
step === 1 step === 1
? "Create Account" ? "Create Account"
: !data.selectedTier : step === 2
? "Continue" ? "I've verified my email"
: data.selectedTier === "free" : !data.selectedTier
? "Start Free Trial" ? "Continue"
: "Subscribe & Continue"; : data.selectedTier === "free"
? "Start Free Trial"
: "Subscribe & Continue";
return ( return (
<div className="subscribe__footer"> <div className="subscribe__footer">
<div> <div>
{step === 2 && ( {step > 1 && (
<Button onClick={handleBack} disabled={loading} variant="ghost"> <Button onClick={handleBack} disabled={loading} variant="ghost">
← Back ← Back
</Button> </Button>
@@ -222,7 +292,7 @@ export default function Subscribe() {
<Button <Button
onClick={handleNext} onClick={handleNext}
disabled={loading || (step === 2 && !data.selectedTier)} disabled={loading || (step === 3 && !data.selectedTier)}
className="text-bold" className="text-bold"
> >
{loading ? "Please wait..." : nextLabel} {loading ? "Please wait..." : nextLabel}
@@ -235,13 +305,14 @@ export default function Subscribe() {
const stepContent = { const stepContent = {
1: StepCreateAccount(), 1: StepCreateAccount(),
2: StepChoosePlan(), 2: StepVerifyEmail(),
3: StepChoosePlan(),
}; };
return ( return (
<div className="subscribe"> <div className="subscribe">
<div <div
className={`subscribe__container${step === 2 ? " subscribe__container--wide" : ""}`} className={`subscribe__container${step === 3 ? " subscribe__container--wide" : ""}`}
> >
<h1 className="subscribe__title">Koin Ping</h1> <h1 className="subscribe__title">Koin Ping</h1>