File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11"use client" ;
22
3+ import { useEffect , useState } from "react" ;
4+ import { User } from "firebase/auth" ; // Adjust the import path based on your Firebase setup
35import { useRouter } from "next/navigation" ;
46import { Plus } from "lucide-react" ;
7+ import { onAuthStateChanged } from "@/lib/firebase/auth" ;
58
69const AddProjectFAB = ( ) => {
710 const router = useRouter ( ) ;
11+ const [ user , setUser ] = useState < User | null > ( null ) ;
12+
13+ useEffect ( ( ) => {
14+ const unsubscribe = onAuthStateChanged ( ( currentUser ) => {
15+ setUser ( currentUser ) ;
16+ } ) ;
17+ return ( ) => unsubscribe ( ) ;
18+ } , [ ] ) ;
819
920 const handleClick = ( ) => {
10- router . push ( "/add-project" ) ; // 🚀 No authentication check
21+ if ( user ) {
22+ router . push ( "/add-project" ) ;
23+ } else {
24+ router . push ( "/login" ) ; // Redirect to login if not authenticated
25+ }
1126 } ;
1227
1328 return (
@@ -37,4 +52,4 @@ const AddProjectFAB = () => {
3752 ) ;
3853} ;
3954
40- export default AddProjectFAB ;
55+ export default AddProjectFAB ;
You can’t perform that action at this time.
0 commit comments