Currently, I am integrating Firebase into my next.js application for user login functionality. The issue I am facing is that users are getting logged out every time they switch paths within the site. Even though their session cookie has not expired, if they navigate to a specific path like /question/page, Firebase automatically logs them out. My goal is to ensure that users remain authenticated until their session cookie expires, regardless of which path they visit on the site. Unfortunately, I cannot use the firebase-admin package as it causes crashes in my next.js environment. Therefore, I have to rely on the standard Firebase package along with the js-cookie library.
componentDidMount() {
let user = firebase_auth.currentUser;
console.log("User: ", user);
if (user) {
this.setState({user_logged_in: true});
return firebase_auth.currentUser.getIdToken(true).then(function (token) {
Cookies.set('__session', token, {expires: 7});
})
}
else {
this.setState({user_logged_in: false})
}
}
I need assistance utilizing the session cookie mentioned in the code above to prevent users from being constantly logged out when navigating between different paths. Any guidance or suggestions would be greatly appreciated!
Thank you in advance for your help!