diff --git a/components/settings/AccountSettings.tsx b/components/settings/AccountSettings.tsx
index 769fe54..eacad76 100644
--- a/components/settings/AccountSettings.tsx
+++ b/components/settings/AccountSettings.tsx
@@ -1,18 +1,24 @@
'use client';
-import { useEffect } from 'react';
+import { useEffect, useState } from 'react';
import { useSearchParams, useRouter } from 'next/navigation';
import { useAuthStore, type LinuxDoUser } from '@/lib/store/auth-store';
import { useHistoryStore } from '@/lib/store/history-store';
import { useSearchHistoryStore } from '@/lib/store/search-history-store';
export function AccountSettings() {
+ const [isHydrated, setIsHydrated] = useState(false);
const searchParams = useSearchParams();
const router = useRouter();
const { user, isAuthenticated, login, logout } = useAuthStore();
const { clearHistory } = useHistoryStore();
const { clearSearchHistory } = useSearchHistoryStore();
+ // Wait for Zustand to hydrate from localStorage
+ useEffect(() => {
+ setIsHydrated(true);
+ }, []);
+
useEffect(() => {
const authSuccess = searchParams.get('auth_success');
const token = searchParams.get('token');
@@ -21,13 +27,9 @@ export function AccountSettings() {
if (authSuccess && token && userStr) {
try {
const userData = JSON.parse(userStr) as LinuxDoUser;
- // Clear existing data before logging in new user
clearHistory();
clearSearchHistory();
-
login(userData, token);
-
- // Clean URL
router.replace('/settings');
} catch (e) {
console.error('Failed to parse user data', e);
@@ -36,7 +38,6 @@ export function AccountSettings() {
}, [searchParams, login, clearHistory, clearSearchHistory, router]);
const handleLogin = () => {
- // Clear data before redirecting to ensure clean state
clearHistory();
clearSearchHistory();
router.push('/api/oauth/authorize');
@@ -48,6 +49,24 @@ export function AccountSettings() {
clearSearchHistory();
};
+ // Don't render until hydrated to prevent flash
+ if (!isHydrated) {
+ return (
+
+ );
+ }
+
return (