···245245 pdsEndpoint: pdsEndpoint // Store the PDS endpoint for later use
246246 });
247247248248- // Clear all auth-related storage items
248248+ // Save the final PDS endpoint to use
249249+ // Prioritize the one from token extraction, then the stored one
250250+ const finalPdsEndpoint = pdsEndpoint || storedPdsEndpoint;
251251+252252+ // Clear only the temporary auth-related items
249253 clearAuthData('oauth_state');
250254 clearAuthData('code_verifier');
251255 clearAuthData('key_pair');
252252- clearAuthData('pds_endpoint');
253256 clearAuthData('auth_server');
254257255255- // Also try to clear any leftover sessionStorage items
256256- try {
257257- sessionStorage.clear();
258258- } catch (e) {
259259- console.warn('Failed to clear session storage:', e);
258258+ // IMPORTANT: Do NOT clear pdsEndpoint since we need it for API calls!
259259+260260+ // Special handling for PDS endpoint - make sure it's in localStorage
261261+ // as both a regular key and in our auth format
262262+ if (finalPdsEndpoint) {
263263+ console.log('Ensuring PDS endpoint is saved for API calls:', finalPdsEndpoint);
264264+265265+ // Save directly to localStorage for legacy code
266266+ localStorage.setItem('pdsEndpoint', finalPdsEndpoint);
267267+268268+ // Also save in our auth format
269269+ localStorage.setItem('bsky_auth_pdsEndpoint', finalPdsEndpoint);
270270+271271+ // And in sessionStorage for good measure
272272+ try {
273273+ sessionStorage.setItem('pdsEndpoint', finalPdsEndpoint);
274274+ } catch (e) {
275275+ console.warn('Could not save pdsEndpoint to sessionStorage:', e);
276276+ }
277277+ } else {
278278+ console.warn('No PDS endpoint found to save. API calls may fail.');
260279 }
261280262281 // Redirect to home page
+38-3
app/src/app/stats/page.tsx
···44import Link from 'next/link';
55import styles from './stats.module.css';
66import { formatRelativeTime } from '@/lib/time-utils';
77+import { useAuth } from '@/lib/auth-context';
7889interface StatsData {
910 totalCount: number;
···1314}
14151516export default function StatsPage() {
1717+ const { isAuthenticated, handle, clearAuth } = useAuth();
1618 const [statsData, setStatsData] = useState<StatsData | null>(null);
1719 const [loading, setLoading] = useState(true);
1820 const [error, setError] = useState<string | null>(null);
2121+2222+ // Function to handle logout
2323+ const handleLogout = () => {
2424+ clearAuth();
2525+ };
19262027 useEffect(() => {
2128 // Fetch stats data when the component mounts
···8087 return (
8188 <div className={styles.container}>
8289 <header className={styles.header}>
8383- <h1>Plumbing Stats 🪠</h1>
8484- <p className={styles.subtitle}>
9090+ <div className={styles.headerContent}>
9191+ <h1 className={styles.title}>im.flushing 🧻</h1>
9292+ <p className={styles.subtitle}>https://flushing.im 🚽</p>
9393+ <p className={styles.description}>
9494+ The world's first decentralized social media app for sharing when you're on the toilet. Connect with other bathroom enjoyers all over the world by posting "flushes"! Powered by the AT Protocol. Your status updates are saved to your PDS with the im.flushing lexicon.<br />
9595+ <span className={styles.creditLine}>
9696+ Made by <a href="https://bsky.app/profile/dame.is" target="_blank" rel="noopener noreferrer">@dame.is</a>.
9797+ Like the app? Consider contributing to <a href="https://ko-fi.com/dameis" target="_blank" rel="noopener noreferrer" className={styles.kofiLink}>my toilet paper fund</a>.
9898+ </span>
9999+ </p>
100100+ </div>
101101+ <div className={styles.headerActions}>
102102+ {isAuthenticated ? (
103103+ <>
104104+ <Link href={`/profile/${handle}`} className={styles.userInfo}>@{handle}</Link>
105105+ <button onClick={handleLogout} className={styles.logoutButton}>
106106+ Logout
107107+ </button>
108108+ </>
109109+ ) : (
110110+ <Link href="/auth/login" className={styles.loginButton}>
111111+ Login with Bluesky
112112+ </Link>
113113+ )}
114114+ </div>
115115+ </header>
116116+117117+ <div className={styles.statsHeader}>
118118+ <h2>Plumbing Stats 🪠</h2>
119119+ <p className={styles.statsSubtitle}>
85120 Global statistics for the im.flushing network
86121 </p>
8787- </header>
122122+ </div>
8812389124 <div className={styles.controls}>
90125 <button