Add auth system with invite-only registration and admin roles
JWT-based auth (hono/jwt + bcrypt), anonymous-first flow preserved. Registration requires invite code when REQUIRE_INVITE=true. Admin user seeded on startup (admin/admin, forced password reset). Login accepts email or username. Admin invitations management page in sidebar. Regular users get invite-a-friend button when USER_INVITATIONS > 0. Frontend gate screen blocks game access for unregistered users with invite code entry, registration, login, and password reset flows. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
+36
-1
@@ -3,10 +3,30 @@ import { useGameStore } from '@/store';
|
||||
import { MainLayout } from '@/components/layout/MainLayout';
|
||||
import { NewGameScreen } from '@/components/game/NewGameScreen';
|
||||
import { OfflineCatchUp } from '@/components/game/OfflineCatchUp';
|
||||
import { InviteGateScreen } from '@/components/game/InviteGateScreen';
|
||||
import { useGameLoop } from '@/hooks/useGameLoop';
|
||||
import { useAuthGate } from '@/hooks/useAuthGate';
|
||||
import { TICK_INTERVAL_MS } from '@ai-tycoon/shared';
|
||||
import { Sparkles } from 'lucide-react';
|
||||
|
||||
function LoadingScreen() {
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center bg-gradient-to-b from-surface-950 to-surface-900">
|
||||
<div className="text-center">
|
||||
<div className="inline-flex items-center gap-2 mb-4">
|
||||
<Sparkles className="text-accent-light animate-pulse" size={32} />
|
||||
<h1 className="text-4xl font-bold bg-gradient-to-r from-accent-light to-accent bg-clip-text text-transparent">
|
||||
AI Tycoon
|
||||
</h1>
|
||||
</div>
|
||||
<p className="text-surface-500 text-sm">Loading...</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function App() {
|
||||
const { loading: authLoading, needsInvite, needsPasswordReset, setRegistered, setNeedsPasswordReset } = useAuthGate();
|
||||
const companyName = useGameStore((s) => s.meta.companyName);
|
||||
const lastTickTimestamp = useGameStore((s) => s.meta.lastTickTimestamp);
|
||||
const [catchUpTicks, setCatchUpTicks] = useState<number | null>(null);
|
||||
@@ -23,7 +43,22 @@ export function App() {
|
||||
}
|
||||
}, [companyName, lastTickTimestamp, catchUpDone]);
|
||||
|
||||
useGameLoop(!catchUpDone);
|
||||
useGameLoop(!catchUpDone || authLoading || needsInvite || needsPasswordReset);
|
||||
|
||||
if (authLoading) {
|
||||
return <LoadingScreen />;
|
||||
}
|
||||
|
||||
if (needsInvite || needsPasswordReset) {
|
||||
return (
|
||||
<InviteGateScreen
|
||||
onRegistered={() => {
|
||||
setRegistered(true);
|
||||
setNeedsPasswordReset(false);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
if (!companyName) {
|
||||
return <NewGameScreen />;
|
||||
|
||||
Reference in New Issue
Block a user