caelum0x aa848c66d0 fix(ritgram): Apple-design unslop pass + Rithub OAuth2 sign-in + critical login-redirect-loop fix
Apple design (plans/gtm/APPLE-DESIGN-RULES-2026-11-17.md): rewrote theme
tokens in globals.css/tailwind.config.js to neutral black/white + one
accent (#0071E3), replacing the GitHub-dark blue+green dual-accent theme;
mechanically swept every raw inline hex/rgba literal across app/components
that bypassed the CSS vars (506 hex + 326 rgb(a) replacements) since most
of the app hardcoded colors rather than using tokens; removed all emoji,
decorative gradients (Tailwind bg-gradient-to-* and raw linear/radial-
gradient() in inline styles), confetti, and glow/blur decorative orbs;
converted Navbar/Navigation to icon-only with aria-label+title. Finished
two stopped agents' in-progress work: deleted the fake AnimatedStats/
LiveActivity/ProjectShowcase/Testimonials auth-panel components and
cleaned up the emoji-laden feature list in (auth)/layout.tsx. Removed
remaining fabricated stats (topics/topics/[slug] posts-per-week/
contributors/followers) per the no-fake-numbers rule.

Rithub sign-in: added "Continue with Rithub" as an icon-only OAuth2
button (RithubMark component) on login/register, hidden "Continue with
GitHub" when GITHUB_CLIENT_ID is unset (confirmed unset in prod). Backend:
authenticateWithGitea in oauthService.ts exchanges the Gitea OAuth2 code,
resolves identity via the existing ForgeConnection table (no schema
migration needed), issues the same JWT/session as GitHub/Google login.
OAuth2 app created live on rithub.dev via its REST API as admin user
caelum0x; client id/secret stored in railyard-box's compose file (env
files don't ship to the runtime image, so the actual wiring lives in
docker-compose.yml, not backend/.env) and in ~/products/.env.

Critical bug found and fixed while verifying: services/api.ts's global
401 interceptor redirected every anonymous visitor to /login a couple
seconds after ANY page load -- including /login and /register themselves
-- because the AuthBootstrap's background GET /auth/me (expected to 401
for signed-out visitors) was treated the same as a real session-expiry
401, triggering a refresh attempt, another 401, and a hard
window.location.href redirect, which re-ran AuthBootstrap and repeated.
Fixed by excluding /auth/me and /auth/refresh from that redirect path.
Verified live with a fresh, cookie-less browser: previously looped
/register -> /login forever; now stable after 6s.

Also fixed: production CORS/API origin mismatch -- the frontend was
built with NEXT_PUBLIC_API_URL pointing at ritgram.ereboslab.com while
served from ritgram.rithub.dev, so every API call (login, register, etc.)
was blocked by CORS; rebuilt with rithub.dev as canonical and CORS_ORIGIN
allowing both domains.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-11-17 17:33:41 +03:00

102 lines
3.0 KiB
TypeScript

'use client';
import { useState, useEffect } from 'react';
import { useRouter } from 'next/navigation';
export default function SubscriptionPage() {
const [subscription, setSubscription] = useState<any>(null);
const [loading, setLoading] = useState(true);
const router = useRouter();
useEffect(() => {
fetchSubscription();
}, []);
const fetchSubscription = async () => {
const res = await fetch('/api/subscriptions', {
credentials: 'include',
});
const data = await res.json();
setSubscription(data);
setLoading(false);
};
const handleUpgrade = async (plan: string) => {
const res = await fetch('/api/subscriptions/checkout', {
method: 'POST',
credentials: 'include',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ plan }),
});
const { url } = await res.json();
window.location.href = url;
};
const handleCancel = async () => {
if (!confirm('Cancel subscription?')) return;
await fetch('/api/subscriptions', {
method: 'DELETE',
credentials: 'include',
});
fetchSubscription();
};
if (loading) return <div className="p-8">Loading...</div>;
return (
<div className="max-w-6xl mx-auto p-8">
<h1 className="text-3xl font-bold mb-8">Subscription</h1>
<div className="grid md:grid-cols-3 gap-6">
<div className="border rounded-lg p-6">
<h2 className="text-xl font-bold mb-2">Free</h2>
<p className="text-3xl font-bold mb-4">$0<span className="text-sm">/mo</span></p>
<ul className="space-y-2 mb-6">
<li> Basic features</li>
<li> 100 posts/month</li>
<li> 1GB storage</li>
</ul>
{subscription?.plan === 'free' && (
<button disabled className="w-full py-2 bg-gray-300 rounded">Current Plan</button>
)}
</div>
<div className="border-2 border-blue-500 rounded-lg p-6">
<div className="text-xs bg-blue-500 text-white px-2 py-1 rounded w-fit mb-2">POPULAR</div>
<h2 className="text-xl font-bold mb-2">Premium</h2>
<p className="text-3xl font-bold mb-4">$9<span className="text-sm">/mo</span></p>
<ul className="space-y-2 mb-6">
<li> All Free features</li>
<li> Verified badge</li>
<li> Custom themes</li>
<li> Ad-free</li>
<li> 10GB storage</li>
</ul>
{subscription?.plan === 'premium' ? (
<button onClick={handleCancel} className="w-full py-2 bg-red-500 text-white rounded">Cancel</button>
) : (
<button onClick={() => handleUpgrade('premium')} className="w-full py-2 bg-blue-500 text-white rounded">Upgrade</button>
)}
</div>
<div className="border rounded-lg p-6">
<h2 className="text-xl font-bold mb-2">Creator</h2>
<p className="text-3xl font-bold mb-4">$29<span className="text-sm">/mo</span></p>
<ul className="space-y-2 mb-6">
<li> All Premium features</li>
<li> Advanced analytics</li>
<li> Content scheduling</li>
<li> Priority support</li>
<li> 100GB storage</li>
</ul>
{subscription?.plan === 'creator' ? (
<button onClick={handleCancel} className="w-full py-2 bg-red-500 text-white rounded">Cancel</button>
) : (
<button onClick={() => handleUpgrade('creator')} className="w-full py-2 bg-blue-500 text-white rounded">Upgrade</button>
)}
</div>
</div>
</div>
);
}