Revert "sadasd"

This reverts commit 9f85ce4f52.
This commit is contained in:
alorig
2025-12-09 00:26:01 +05:00
parent 9f85ce4f52
commit 92d16c76a7
11 changed files with 198 additions and 774 deletions

View File

@@ -39,26 +39,15 @@ export default function ProtectedRoute({ children }: ProtectedRouteProps) {
// Validate account + plan whenever auth/user changes
useEffect(() => {
console.log('[ProtectedRoute] Auth state changed:', {
isAuthenticated,
hasUser: !!user,
hasAccount: !!user?.account,
pathname: location.pathname
});
if (!isAuthenticated) {
console.log('[ProtectedRoute] Not authenticated, will redirect to signin');
return;
}
if (!user?.account) {
console.error('[ProtectedRoute] User has no account, logging out');
setErrorMessage('This user is not linked to an account. Please contact support.');
logout();
return;
}
console.log('[ProtectedRoute] Auth validation passed');
}, [isAuthenticated, user, logout]);
// Immediate check on mount: if loading is true, reset it immediately
@@ -125,7 +114,6 @@ export default function ProtectedRoute({ children }: ProtectedRouteProps) {
// Redirect to signin if not authenticated
if (!isAuthenticated) {
console.log('[ProtectedRoute] Redirecting to /signin - not authenticated');
return <Navigate to="/signin" state={{ from: location }} replace />;
}

View File

@@ -28,11 +28,6 @@ export default function SignInForm() {
try {
await login(email, password);
// CRITICAL: Wait for auth state to persist to localStorage before navigating
// Increased to 500ms to ensure Zustand persist middleware completes
await new Promise(resolve => setTimeout(resolve, 500));
// Redirect to the page user was trying to access, or home
const from = (location.state as any)?.from?.pathname || "/";
navigate(from, { replace: true });

View File

@@ -85,11 +85,9 @@ export default function SignUpForm({ planDetails: planDetailsProp, planLoading:
}
try {
console.log('[SignUp] Starting registration...');
// Generate username from email if not provided
const username = formData.username || formData.email.split("@")[0];
console.log('[SignUp] Calling register API...');
const user = await register({
email: formData.email,
password: formData.password,
@@ -100,29 +98,13 @@ export default function SignUpForm({ planDetails: planDetailsProp, planLoading:
plan_slug: planSlug || undefined,
});
console.log('[SignUp] Registration successful, user:', user);
console.log('[SignUp] Auth state before delay:', useAuthStore.getState());
// CRITICAL: Wait for auth state to persist to localStorage before navigating
// Increased to 500ms to ensure Zustand persist middleware completes
await new Promise(resolve => setTimeout(resolve, 500));
// Verify auth state is persisted
const persistedState = localStorage.getItem('auth-storage');
console.log('[SignUp] Persisted auth state:', persistedState);
console.log('[SignUp] Auth state after delay:', useAuthStore.getState());
const status = user?.account?.status;
console.log('[SignUp] Account status:', status);
if (status === "pending_payment") {
console.log('[SignUp] Navigating to /account/plans');
navigate("/account/plans", { replace: true });
} else {
console.log('[SignUp] Navigating to /sites');
navigate("/sites", { replace: true });
}
} catch (err: any) {
console.error('[SignUp] Registration error:', err);
setError(err.message || "Registration failed. Please try again.");
}
};

View File

@@ -35,7 +35,6 @@ interface AuthState {
refreshToken: string | null;
isAuthenticated: boolean;
loading: boolean;
_hasHydrated: boolean; // Track if persist has completed rehydration
// Actions
login: (email: string, password: string) => Promise<void>;
@@ -45,7 +44,6 @@ interface AuthState {
setToken: (token: string | null) => void;
refreshToken: () => Promise<void>;
refreshUser: () => Promise<void>;
setHasHydrated: (hasHydrated: boolean) => void;
}
export const useAuthStore = create<AuthState>()(
@@ -55,7 +53,6 @@ export const useAuthStore = create<AuthState>()(
token: null,
isAuthenticated: false,
loading: false, // Always start with loading false - will be set true only during login/register
_hasHydrated: false, // Will be set to true after persist rehydration completes
login: async (email, password) => {
set({ loading: true });