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