Skip to content

Commit 0dd034b

Browse files
committed
adding auth to add Project again
1 parent 217f620 commit 0dd034b

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

components/repeto/AddProjectFAB.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
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
35
import { useRouter } from "next/navigation";
46
import { Plus } from "lucide-react";
7+
import { onAuthStateChanged } from "@/lib/firebase/auth";
58

69
const 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;

0 commit comments

Comments
 (0)