Im new to Next.js development. Im following a Youtube tutorial to build a Whatsapp clone. Im using firebase8.9 as the database
I want to check if the user is logged in, then go to the home page else redirect to the login page.
import '../styles/globals.css'
import { useAuthState } from "react-firebase-hooks/auth"
import { auth, db } from "../firebase"
import Login from "./login"
function MyApp({ Component, pageProps }) {
const [user] = useAuthState(auth);
return <Component {...pageProps} />;
}
export default MyApp
my firebase.js file
import firebase from 'firebase';
const firebaseConfig = {
apiKey: "apikey",
authDomain: "authdomain",
projectId: "projectid",
storageBucket: "storagebucket",
messagingSenderId: "messagingsenderid",
appId: "appid"
};
const app = !firebase.apps.length ? firebase.initializeApp(firebaseConfig) : firebase.app();
const db = app.firestore();
const auth = app.auth();
const provider = new firebase.auth.GoogleAuthProvider();
export { db, auth, provider };
Please help me to solve this problem. Thanks in advance!
As the time, firebase version is upgraded as of now to version 9+ as well as the firebase hooks changing the entire structure. So, what you simply need to do is go to your package.json file and change your "firebase" version to "firebase": "8.0.0".
Now look for "react-firebase-hooks" in the same package.json file and change its version to "react-firebase-hooks": "^3.0.4" from the current version.
Now, open up your terminal and run yarn install, this will solve the version issue.
Was stuck on the same error
Just go to the node modules and change the version of react-firebase-hook from 4.0.0 to 3.0.4.
And then a simple yarn install will solve the issue...