fix(auth): scanner redirect + admin card-editor crash #36

Merged
varutasu merged 1 commit from fix/auth-loading-and-admin-hooks into main 2026-05-27 13:36:59 -04:00
3 changed files with 14 additions and 36 deletions

View file

@ -9,22 +9,6 @@ const CardEditor = () => {
const router = useRouter();
const { id } = router.query;
const [mounted, setMounted] = useState(false);
useEffect(() => {
setMounted(true);
}, []);
if (!mounted) {
return (
<Layout user={null}>
<div className="flex items-center justify-center min-h-screen">
<div className="animate-spin rounded-full h-32 w-32 border-b-2" style={{ borderColor: 'var(--text-accent)' }}></div>
</div>
</Layout>
);
}
const [card, setCard] = useState(null);
const [loading, setLoading] = useState(true);
const [saving, setSaving] = useState(false);

View file

@ -5,21 +5,6 @@ import Layout from '../../components/Layout';
import AdminProtected from '../../components/AdminProtected';
const CardImport = () => {
const [mounted, setMounted] = useState(false);
useEffect(() => {
setMounted(true);
}, []);
if (!mounted) {
return (
<Layout user={null}>
<div className="flex items-center justify-center min-h-screen">
<div className="animate-spin rounded-full h-32 w-32 border-b-2" style={{ borderColor: 'var(--text-accent)' }}></div>
</div>
</Layout>
);
}
const router = useRouter();
const [importType, setImportType] = useState('mtg');
const [setCode, setSetCode] = useState('');

View file

@ -8,7 +8,7 @@ import ManaSymbolSettings from '../components/ManaSymbolSettings';
import { useAuth } from '../lib/use-auth';
export default function Scanner() {
const { user } = useAuth();
const { user, loading: authLoading } = useAuth();
const router = useRouter();
const [scannedCards, setScannedCards] = useState([]);
const [collections, setCollections] = useState([]);
@ -26,13 +26,12 @@ export default function Scanner() {
// Mana symbol settings
const [manaSymbolSettings, setManaSymbolSettings] = useState({ useSVG: false });
// Redirect to login if not authenticated
// Redirect to login if not authenticated (wait for verify to finish)
useEffect(() => {
if (!user) {
if (!authLoading && !user) {
router.push('/login');
return;
}
}, [user, router]);
}, [authLoading, user, router]);
// Load collections and decks
useEffect(() => {
@ -325,6 +324,16 @@ export default function Scanner() {
setSelectedCards(new Set());
};
if (authLoading) {
return (
<Layout user={null}>
<div className="flex items-center justify-center min-h-[50vh]">
<div className="animate-spin rounded-full h-12 w-12 border-b-2" style={{ borderColor: 'var(--text-accent)' }} />
</div>
</Layout>
);
}
if (!user) {
return <div>Redirecting to login...</div>;
}