Compare commits

...

11 Commits

Author SHA1 Message Date
KS Jannette
cea031334e add comment 2026-05-12 05:18:33 -04:00
KS Jannette
c4371f7886 fixed login race condition 2026-05-12 05:14:12 -04:00
KS Jannette
8b2db08db1 simplified auth context provider 2026-05-12 04:53:53 -04:00
KS Jannette
f52f7dc89f more style update for mobile 2026-05-12 01:09:41 -04:00
KS Jannette
3eab5d07ff more style 2026-05-12 01:00:33 -04:00
KS Jannette
83ac4b7c14 more style hotfix 2026-05-12 00:52:39 -04:00
KS Jannette
5eca679f54 hotfix 2026-05-12 00:48:01 -04:00
S Jannette
f4e6953046 Merge pull request #37 from kjannette/mobile-style
Adjust css for login page
2026-05-12 00:39:00 -04:00
KS Jannette
8c1d214897 Adjust css for login page 2026-05-12 00:37:39 -04:00
KS Jannette
71443f0abc hotfix 2026-05-11 22:34:23 -04:00
S Jannette
d89970fcac Merge pull request #36 from kjannette/verify-email
add email verification step to new user onboarding flow
2026-05-11 22:26:44 -04:00
7 changed files with 104 additions and 64 deletions

View File

@@ -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 (

View File

@@ -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;
}
}

View File

@@ -1,4 +1,4 @@
import { createContext, useContext, useState, useEffect, useCallback } from "react"; import { createContext, useContext, useSyncExternalStore } from "react";
import { import {
onAuthStateChanged, onAuthStateChanged,
signInWithEmailAndPassword, signInWithEmailAndPassword,
@@ -17,86 +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);
}
async function sendEmailVerification() { 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) { if (auth.currentUser) {
await firebaseSendEmailVerification(auth.currentUser); return firebaseSendEmailVerification(auth.currentUser);
} }
} };
async function reloadUser() { const reloadUser = async () => {
if (auth.currentUser) { if (auth.currentUser) {
await auth.currentUser.reload(); await auth.currentUser.reload();
setCurrentUser({ ...auth.currentUser }); return auth.currentUser;
} }
} return null;
};
const value = { const value = {
currentUser, ...state,
userTier,
tierLimits,
isSubscribed,
loading,
signup, signup,
login, login,
logout, logout,
sendEmailVerification, sendEmailVerification,
reloadUser, reloadUser,
refreshAccount: fetchAccount, 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() {

View File

@@ -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;
}
} }

View File

@@ -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;
}
} }

View File

@@ -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">

View File

@@ -82,10 +82,7 @@ export default function Subscribe() {
setError(""); setError("");
setLoading(true); setLoading(true);
try { try {
await reloadUser(); const user = await reloadUser();
const { currentUser: user } = await import("../../firebase/config").then(
(m) => ({ currentUser: m.auth.currentUser })
);
if (user?.emailVerified) { if (user?.emailVerified) {
setStep(3); setStep(3);
} else { } else {