fix: Prevent redirect to login on dealer apply page during auth loading

Wait for isLoading to complete before checking user state to avoid
premature redirect when navigating from profile page.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
AutonetSellCar Deploy
2026-03-27 16:44:08 +09:00
parent e274bc763d
commit a5a87e78e8

View File

@@ -27,7 +27,7 @@ interface DealerApplication {
export default function DealerApplyPage() {
const { t, language } = useTranslation();
const { user, token } = useAuthStore();
const { user, token, isLoading } = useAuthStore();
const router = useRouter();
const [loading, setLoading] = useState(false);
@@ -53,6 +53,8 @@ export default function DealerApplyPage() {
});
useEffect(() => {
if (isLoading) return;
if (!user) {
router.push('/login');
return;
@@ -65,7 +67,7 @@ export default function DealerApplyPage() {
// Check for existing application
checkExistingApplication();
}, [user, router]);
}, [user, router, isLoading]);
const checkExistingApplication = async () => {
if (!token) return;
@@ -121,7 +123,7 @@ export default function DealerApplyPage() {
}
};
if (!user || checkingApplication) {
if (isLoading || !user || checkingApplication) {
return (
<div className="min-h-screen bg-gray-50 flex items-center justify-center">
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-primary-600"></div>