forked from cardosofelipe/fast-next-template
**Authentication Refactor:** Remove authStore and its associated tests, transitioning to the new authentication model. Add dynamic loading for PasswordResetConfirmForm to optimize performance. Include a theme initialization script in layout.tsx to prevent FOUC.
This commit is contained in:
@@ -7,10 +7,23 @@
|
||||
|
||||
import { useSearchParams, useRouter } from 'next/navigation';
|
||||
import { useEffect, useRef } from 'react';
|
||||
import { PasswordResetConfirmForm } from '@/components/auth/PasswordResetConfirmForm';
|
||||
import dynamic from 'next/dynamic';
|
||||
import { Alert } from '@/components/ui/alert';
|
||||
import Link from 'next/link';
|
||||
|
||||
// Code-split PasswordResetConfirmForm (319 lines)
|
||||
const PasswordResetConfirmForm = dynamic(
|
||||
() => import('@/components/auth/PasswordResetConfirmForm').then((mod) => ({ default: mod.PasswordResetConfirmForm })),
|
||||
{
|
||||
loading: () => (
|
||||
<div className="space-y-4">
|
||||
<div className="animate-pulse h-10 bg-muted rounded" />
|
||||
<div className="animate-pulse h-10 bg-muted rounded" />
|
||||
</div>
|
||||
),
|
||||
}
|
||||
);
|
||||
|
||||
export default function PasswordResetConfirmContent() {
|
||||
const searchParams = useSearchParams();
|
||||
const router = useRouter();
|
||||
|
||||
@@ -1,6 +1,20 @@
|
||||
'use client';
|
||||
|
||||
import { RegisterForm } from '@/components/auth/RegisterForm';
|
||||
import dynamic from 'next/dynamic';
|
||||
|
||||
// Code-split RegisterForm (313 lines)
|
||||
const RegisterForm = dynamic(
|
||||
() => import('@/components/auth/RegisterForm').then((mod) => ({ default: mod.RegisterForm })),
|
||||
{
|
||||
loading: () => (
|
||||
<div className="space-y-4">
|
||||
<div className="animate-pulse h-10 bg-muted rounded" />
|
||||
<div className="animate-pulse h-10 bg-muted rounded" />
|
||||
<div className="animate-pulse h-10 bg-muted rounded" />
|
||||
</div>
|
||||
),
|
||||
}
|
||||
);
|
||||
|
||||
export default function RegisterPage() {
|
||||
return (
|
||||
|
||||
@@ -24,7 +24,33 @@ export default function RootLayout({
|
||||
children: React.ReactNode;
|
||||
}>) {
|
||||
return (
|
||||
<html lang="en">
|
||||
<html lang="en" suppressHydrationWarning>
|
||||
<head>
|
||||
{/* Theme initialization script - runs before React hydrates to prevent FOUC */}
|
||||
<script
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: `
|
||||
(function() {
|
||||
try {
|
||||
const theme = localStorage.getItem('theme') || 'system';
|
||||
let resolved;
|
||||
|
||||
if (theme === 'system') {
|
||||
resolved = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
||||
} else {
|
||||
resolved = theme;
|
||||
}
|
||||
|
||||
document.documentElement.classList.remove('light', 'dark');
|
||||
document.documentElement.classList.add(resolved);
|
||||
} catch (e) {
|
||||
// Silently fail - theme will be set by ThemeProvider
|
||||
}
|
||||
})();
|
||||
`,
|
||||
}}
|
||||
/>
|
||||
</head>
|
||||
<body
|
||||
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
|
||||
>
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
|
||||
import { useState } from 'react';
|
||||
import { AuthInitializer } from '@/components/auth';
|
||||
import { ThemeProvider } from '@/components/theme';
|
||||
|
||||
export function Providers({ children }: { children: React.ReactNode }) {
|
||||
@@ -14,7 +13,8 @@ export function Providers({ children }: { children: React.ReactNode }) {
|
||||
queries: {
|
||||
staleTime: 60 * 1000, // 1 minute
|
||||
retry: 1,
|
||||
refetchOnWindowFocus: true,
|
||||
refetchOnWindowFocus: false, // Disabled - use selective refetching per query
|
||||
refetchOnReconnect: true, // Keep for session data
|
||||
},
|
||||
mutations: {
|
||||
retry: false,
|
||||
@@ -26,7 +26,7 @@ export function Providers({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
<ThemeProvider>
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<AuthInitializer />
|
||||
{/* AuthInitializer removed - Zustand persist middleware handles auto-hydration */}
|
||||
{children}
|
||||
<ReactQueryDevtools initialIsOpen={false} />
|
||||
</QueryClientProvider>
|
||||
|
||||
Reference in New Issue
Block a user