forked from cardosofelipe/fast-next-template
fix(frontend): redirect authenticated users to dashboard from landing page
- Added auth check in landing page using `useAuth`. - Redirect authenticated users to `/dashboard`. - Display blank screen during auth verification or redirection.
This commit is contained in:
@@ -3,12 +3,16 @@
|
||||
* Homepage / Landing Page
|
||||
* Main landing page for the Syndarix project
|
||||
* Showcases features, tech stack, and provides demos for developers
|
||||
*
|
||||
* If user is authenticated, redirects to dashboard
|
||||
*/
|
||||
|
||||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
import { Link } from '@/lib/i18n/routing';
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Link, useRouter } from '@/lib/i18n/routing';
|
||||
import { useAuth } from '@/lib/auth/AuthContext';
|
||||
import config from '@/config/app.config';
|
||||
import { Header } from '@/components/home/Header';
|
||||
import { HeroSection } from '@/components/home/HeroSection';
|
||||
import { ContextSection } from '@/components/home/ContextSection';
|
||||
@@ -24,6 +28,20 @@ import { DemoCredentialsModal } from '@/components/home/DemoCredentialsModal';
|
||||
|
||||
export default function Home() {
|
||||
const [demoModalOpen, setDemoModalOpen] = useState(false);
|
||||
const router = useRouter();
|
||||
const { isAuthenticated, isLoading } = useAuth();
|
||||
|
||||
// Redirect authenticated users to dashboard
|
||||
useEffect(() => {
|
||||
if (!isLoading && isAuthenticated) {
|
||||
router.push(config.routes.dashboard);
|
||||
}
|
||||
}, [isLoading, isAuthenticated, router]);
|
||||
|
||||
// Show nothing while checking auth or redirecting
|
||||
if (isLoading || isAuthenticated) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen">
|
||||
|
||||
Reference in New Issue
Block a user