Compare commits
13 Commits
config-upd
...
fix-login
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cea031334e | ||
|
|
c4371f7886 | ||
|
|
8b2db08db1 | ||
|
|
f52f7dc89f | ||
|
|
3eab5d07ff | ||
|
|
83ac4b7c14 | ||
|
|
5eca679f54 | ||
|
|
f4e6953046 | ||
|
|
8c1d214897 | ||
|
|
71443f0abc | ||
|
|
d89970fcac | ||
|
|
6b07d51cb1 | ||
|
|
3c282c589c |
@@ -11,9 +11,7 @@ import AlertHistory from "./pages/alertHistory/AlertHistory";
|
|||||||
import Account from "./pages/user_account/Account";
|
import Account from "./pages/user_account/Account";
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
const { currentUser, isSubscribed, loading } = useAuth();
|
const { currentUser, isSubscribed } = useAuth();
|
||||||
|
|
||||||
if (loading) return null;
|
|
||||||
|
|
||||||
if (!currentUser) {
|
if (!currentUser) {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -76,3 +76,14 @@
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
transition: all 0.15s ease;
|
transition: all 0.15s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@media (max-width: 480px) {
|
||||||
|
.nav-panel__overlay {
|
||||||
|
position: fixed;
|
||||||
|
inset: 0;
|
||||||
|
background-color: rgba(0, 0, 0, 0.45);
|
||||||
|
opacity: 0;
|
||||||
|
z-index: 900;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
import { createContext, useContext, useState, useEffect, useCallback } from "react";
|
import { createContext, useContext, useSyncExternalStore } from "react";
|
||||||
import {
|
import {
|
||||||
onAuthStateChanged,
|
onAuthStateChanged,
|
||||||
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";
|
||||||
@@ -16,71 +17,98 @@ const DEFAULT_TIER_LIMITS = {
|
|||||||
allowed_channels: ["email"],
|
allowed_channels: ["email"],
|
||||||
};
|
};
|
||||||
|
|
||||||
export function AuthProvider({ children }) {
|
// External auth store - lives outside React
|
||||||
const [currentUser, setCurrentUser] = useState(null);
|
const createAuthStore = () => {
|
||||||
const [userTier, setUserTier] = useState("free");
|
let state = {
|
||||||
const [tierLimits, setTierLimits] = useState(DEFAULT_TIER_LIMITS);
|
currentUser: null,
|
||||||
const [isSubscribed, setIsSubscribed] = useState(false);
|
userTier: "free",
|
||||||
const [loading, setLoading] = useState(true);
|
tierLimits: DEFAULT_TIER_LIMITS,
|
||||||
|
isSubscribed: false,
|
||||||
|
loading: true,
|
||||||
|
};
|
||||||
|
const listeners = new Set();
|
||||||
|
|
||||||
const fetchAccount = useCallback(async () => {
|
const notify = () => listeners.forEach((fn) => fn());
|
||||||
|
|
||||||
|
const setState = (partial) => {
|
||||||
|
state = { ...state, ...partial };
|
||||||
|
notify();
|
||||||
|
};
|
||||||
|
|
||||||
|
const fetchAccount = async () => {
|
||||||
try {
|
try {
|
||||||
const data = await getAccount();
|
const data = await getAccount();
|
||||||
setUserTier(data.subscription_tier || "free");
|
setState({
|
||||||
setTierLimits(data.tier_limits || DEFAULT_TIER_LIMITS);
|
userTier: data.subscription_tier || "free",
|
||||||
setIsSubscribed(
|
tierLimits: data.tier_limits || DEFAULT_TIER_LIMITS,
|
||||||
data.subscription_status === "active" ||
|
isSubscribed:
|
||||||
|
data.subscription_status === "active" ||
|
||||||
data.subscription_status === "trialing",
|
data.subscription_status === "trialing",
|
||||||
);
|
});
|
||||||
} catch {
|
} catch {
|
||||||
setUserTier("free");
|
setState({ isSubscribed: false });
|
||||||
setTierLimits(DEFAULT_TIER_LIMITS);
|
|
||||||
setIsSubscribed(false);
|
|
||||||
}
|
}
|
||||||
}, []);
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
// Set up Firebase listener once, outside of React
|
||||||
const unsubscribe = onAuthStateChanged(auth, async (user) => {
|
onAuthStateChanged(auth, async (user) => {
|
||||||
setCurrentUser(user);
|
setState({ loading: true, currentUser: user });
|
||||||
if (user) {
|
if (user) {
|
||||||
await fetchAccount();
|
await fetchAccount();
|
||||||
} else {
|
} else {
|
||||||
setUserTier("free");
|
setState({ isSubscribed: false, userTier: "free", tierLimits: DEFAULT_TIER_LIMITS });
|
||||||
setTierLimits(DEFAULT_TIER_LIMITS);
|
}
|
||||||
setIsSubscribed(false);
|
setState({ loading: false });
|
||||||
}
|
});
|
||||||
setLoading(false);
|
|
||||||
});
|
|
||||||
return unsubscribe;
|
|
||||||
}, [fetchAccount]);
|
|
||||||
|
|
||||||
async function signup(email, password) {
|
return {
|
||||||
const cred = await createUserWithEmailAndPassword(auth, email, password);
|
subscribe: (listener) => {
|
||||||
return cred.user;
|
listeners.add(listener);
|
||||||
}
|
return () => listeners.delete(listener);
|
||||||
|
},
|
||||||
|
getSnapshot: () => state,
|
||||||
|
refreshAccount: fetchAccount,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
async function login(email, password) {
|
const authStore = createAuthStore();
|
||||||
const cred = await signInWithEmailAndPassword(auth, email, password);
|
|
||||||
return cred.user;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function logout() {
|
export function AuthProvider({ children }) {
|
||||||
await signOut(auth);
|
const state = useSyncExternalStore(authStore.subscribe, authStore.getSnapshot);
|
||||||
}
|
|
||||||
|
const signup = (email, password) => createUserWithEmailAndPassword(auth, email, password);
|
||||||
|
const login = (email, password) => signInWithEmailAndPassword(auth, email, password);
|
||||||
|
const logout = () => signOut(auth);
|
||||||
|
|
||||||
|
const sendEmailVerification = () => {
|
||||||
|
if (auth.currentUser) {
|
||||||
|
return firebaseSendEmailVerification(auth.currentUser);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const reloadUser = async () => {
|
||||||
|
if (auth.currentUser) {
|
||||||
|
await auth.currentUser.reload();
|
||||||
|
return auth.currentUser;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
const value = {
|
const value = {
|
||||||
currentUser,
|
...state,
|
||||||
userTier,
|
|
||||||
tierLimits,
|
|
||||||
isSubscribed,
|
|
||||||
loading,
|
|
||||||
signup,
|
signup,
|
||||||
login,
|
login,
|
||||||
logout,
|
logout,
|
||||||
refreshAccount: fetchAccount,
|
sendEmailVerification,
|
||||||
|
reloadUser,
|
||||||
|
refreshAccount: authStore.refreshAccount,
|
||||||
};
|
};
|
||||||
|
|
||||||
return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;
|
return (
|
||||||
|
<AuthContext.Provider value={value}>
|
||||||
|
{!state.loading && children}
|
||||||
|
</AuthContext.Provider>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useAuth() {
|
export function useAuth() {
|
||||||
|
|||||||
@@ -422,7 +422,7 @@ button {
|
|||||||
|
|
||||||
.btn {
|
.btn {
|
||||||
padding: 0.45rem 0.85rem;
|
padding: 0.45rem 0.85rem;
|
||||||
font-size: 0.95rem;
|
font-size: 1.45rem !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn--lg {
|
.btn--lg {
|
||||||
@@ -433,4 +433,8 @@ button {
|
|||||||
.section {
|
.section {
|
||||||
padding: 0.75rem;
|
padding: 0.75rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.mb-lg {
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -40,6 +40,7 @@
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
position: relative;
|
position: relative;
|
||||||
top: -20px;
|
top: -20px;
|
||||||
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.login-brand {
|
.login-brand {
|
||||||
@@ -114,4 +115,21 @@
|
|||||||
padding-right: 1rem;
|
padding-right: 1rem;
|
||||||
font-size: 1.25rem;
|
font-size: 1.25rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.login-span {
|
||||||
|
color: red
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
font-weight: 400 !important
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-bg-video {
|
||||||
|
opacity: 0.135;
|
||||||
|
left: 47%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-button {
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -47,7 +47,7 @@ export default function Login() {
|
|||||||
|
|
||||||
<div className="login-card login-card-fadein">
|
<div className="login-card login-card-fadein">
|
||||||
<h1 className="login-heading">
|
<h1 className="login-heading">
|
||||||
<span className="login-brand">Koin Ping</span> - Login
|
<span className="login-brand">Koin Ping</span><span className="login-span"> - Login</span>
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
<div className="login-interactive-fadein">
|
<div className="login-interactive-fadein">
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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,41 @@ export default function Subscribe() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function handleStep2() {
|
async function handleStep2() {
|
||||||
|
setError("");
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
const user = await reloadUser();
|
||||||
|
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 +213,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 +258,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 +269,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 +289,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 +302,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>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user