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

187 lines
6.4 KiB
TypeScript

'use client';
import Link from 'next/link';
import { usePathname } from 'next/navigation';
import AccountSwitcher from './AccountSwitcher';
import SearchBar from './SearchBar';
import { useAuthStore } from '@/store/authStore';
interface NavLink {
href: string;
label: string;
icon: React.ReactNode;
}
const ICON_PROPS = {
className: 'w-5 h-5',
fill: 'none' as const,
stroke: 'currentColor' as const,
viewBox: '0 0 24 24',
'aria-hidden': true as const,
};
export default function Navigation() {
const pathname = usePathname();
const isAuthenticated = useAuthStore((s) => s.isAuthenticated);
// Public links accessible to all users
const publicLinks: NavLink[] = [
{
href: '/',
label: 'Home',
icon: (
<svg {...ICON_PROPS}>
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6" />
</svg>
),
},
{
href: '/discover',
label: 'Discover',
icon: (
<svg {...ICON_PROPS}>
<circle cx="12" cy="12" r="9" strokeWidth={2} />
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M15 9l-2 5-5 2 2-5z" />
</svg>
),
},
{
href: '/explore/repos',
label: 'Explore',
icon: (
<svg {...ICON_PROPS}>
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" />
</svg>
),
},
];
// Protected links only shown when authenticated
const protectedLinks: NavLink[] = [
{
href: '/saved/repos',
label: 'Following',
icon: (
<svg {...ICON_PROPS}>
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4" />
</svg>
),
},
{
href: '/messages',
label: 'Messages',
icon: (
<svg {...ICON_PROPS}>
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z" />
</svg>
),
},
{
href: '/notifications',
label: 'Notifications',
icon: (
<svg {...ICON_PROPS}>
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M15 17h5l-1.4-1.4A2 2 0 0118 14.2V11a6 6 0 10-12 0v3.2a2 2 0 01-.6 1.4L4 17h5m6 0v1a3 3 0 11-6 0v-1m6 0H9" />
</svg>
),
},
{
href: '/profile',
label: 'Profile',
icon: (
<svg {...ICON_PROPS}>
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5.121 17.804A9 9 0 1118.879 17.804M12 11a3 3 0 100-6 3 3 0 000 6z" />
</svg>
),
},
{
href: '/settings/account',
label: 'Settings',
icon: (
<svg {...ICON_PROPS}>
<circle cx="12" cy="12" r="3" strokeWidth={2} />
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19.4 15a1.65 1.65 0 00.33 1.82l.06.06a2 2 0 11-2.83 2.83l-.06-.06a1.65 1.65 0 00-1.82-.33 1.65 1.65 0 00-1 1.51V21a2 2 0 11-4 0v-.09a1.65 1.65 0 00-1-1.51 1.65 1.65 0 00-1.82.33l-.06.06a2 2 0 11-2.83-2.83l.06-.06a1.65 1.65 0 00.33-1.82 1.65 1.65 0 00-1.51-1H3a2 2 0 110-4h.09a1.65 1.65 0 001.51-1 1.65 1.65 0 00-.33-1.82l-.06-.06a2 2 0 112.83-2.83l.06.06a1.65 1.65 0 001.82.33h0a1.65 1.65 0 001-1.51V3a2 2 0 114 0v.09a1.65 1.65 0 001 1.51h0a1.65 1.65 0 001.82-.33l.06-.06a2 2 0 112.83 2.83l-.06.06a1.65 1.65 0 00-.33 1.82v0a1.65 1.65 0 001.51 1H21a2 2 0 110 4h-.09a1.65 1.65 0 00-1.51 1z" />
</svg>
),
},
{
href: '/claim',
label: 'Claim repo',
icon: (
<svg {...ICON_PROPS}>
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
),
},
{
href: '/tools/repo-to-text',
label: 'Repo to text',
icon: (
<svg {...ICON_PROPS}>
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 17H5a2 2 0 01-2-2V5a2 2 0 012-2h7l5 5v3m-6 9l4-4m0 4l-4-4" />
</svg>
),
},
{
href: '/tools/analyze',
label: 'AI analyze',
icon: (
<svg {...ICON_PROPS}>
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a4 4 0 115.072 0A4 4 0 009 16.9z" />
</svg>
),
},
{
href: '/reels',
label: 'Reels',
icon: (
<svg {...ICON_PROPS}>
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M15 10l4.553-2.276A1 1 0 0121 8.618v6.764a1 1 0 01-1.447.894L15 14M5 18h8a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v8a2 2 0 002 2z" />
</svg>
),
},
];
// Combine links based on authentication state
const links = isAuthenticated
? [...publicLinks, ...protectedLinks]
: publicLinks;
return (
<nav className="bg-background border-b border-border sticky top-0 z-50">
<div className="max-w-7xl mx-auto px-4">
<div className="flex items-center justify-between h-16">
<div className="flex items-center gap-8">
<Link href="/" className="text-xl font-bold text-foreground">
Ritgram
</Link>
<div className="hidden md:flex gap-2">
{links.map((link) => (
<Link
key={link.href}
href={link.href}
aria-label={link.label}
title={link.label}
className={`flex items-center justify-center w-10 h-10 rounded-full transition ${
pathname === link.href
? 'bg-surface-secondary text-primary'
: 'text-foreground-secondary hover:bg-surface-secondary hover:text-foreground'
}`}
>
{link.icon}
</Link>
))}
</div>
</div>
<div className="hidden md:flex flex-1 max-w-md mx-8">
<SearchBar placeholder="Search or paste GitHub URL..." />
</div>
<AccountSwitcher />
</div>
</div>
</nav>
);
}