Skip to content

Commit

Permalink
basic admin side login + managing and adding events
Browse files Browse the repository at this point in the history
@AkshadGawde needs lot of ui refinement, default style sheet makes it look very messy.

make sure you have the env setup locally for testing
  • Loading branch information
bhavyachopra99 committed Sep 28, 2024
1 parent eca4f8c commit 72372db
Show file tree
Hide file tree
Showing 9 changed files with 2,264 additions and 80 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules
.next
*.local
.env.local
20 changes: 20 additions & 0 deletions lib/firebase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { initializeApp } from "firebase/app";
import { getAuth } from 'firebase/auth';
import { getFirestore } from 'firebase/firestore';


const firebaseConfig = {
apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY,
authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN,
projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID,
storageBucket: process.env.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET,
messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID,
appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID,
};

const app = initializeApp(firebaseConfig);
const db = getFirestore(app);
const auth = getAuth(app);


export { db , auth};
25 changes: 25 additions & 0 deletions lib/withAuth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// lib/withAuth.js
import { useEffect } from 'react';
import { useRouter } from 'next/router';
import { auth } from '../lib/firebase'; // Import Firebase auth

const withAuth = (WrappedComponent) => {
return (props) => {
const router = useRouter();

useEffect(() => {
const unsubscribe = auth.onAuthStateChanged((user) => {
if (!user) {
// If no user, redirect to login page
router.push('/login');
}
});

return () => unsubscribe(); // Cleanup subscription on unmount
}, []);

return <WrappedComponent {...props} />;
};
};

export default withAuth;
Loading

0 comments on commit 72372db

Please sign in to comment.