Got it! I had the same problem on my Tab View React App. No one responded.
https://forum.framework7.io/t/react-tab-view-firebase-auth-state/
First I did using localStorage
var currentUser = firebase.auth().currentUser;
var user = {
//assign provided data to user object
}
//store data in LocalStorage
localStorage.setItem('userData', JSON.stringify(user));
Then in any page
componentDidMount() {
// console.log('Home - componentDidMount :: init');
const user = JSON.parse(localStorage.getItem('userData'));
}
Second one is setting user object in root data f7param
// Framework7 Parameters
const f7params = {
id: 'unify-travel.web.app',
version: '1.0.3',
name: 'uTravel', // App name
theme: 'auto', // Automatic theme detection
// App root data
data: function () {
return {
// Demo products for Catalog section
products: [
{
id: '1',
title: 'Apple iPhone 8',
description: 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nisi tempora similique reiciendis, error nesciunt vero, blanditiis pariatur dolor, minima sed sapiente rerum, dolorem corrupti hic modi praesentium unde saepe perspiciatis.'
},
{
id: '2',
title: 'Apple iPhone 8 Plus',
description: 'Velit odit autem modi saepe ratione totam minus, aperiam, labore quia provident temporibus quasi est ut aliquid blanditiis beatae suscipit odio vel! Nostrum porro sunt sint eveniet maiores, dolorem itaque!'
},
{
id: '3',
title: 'Apple iPhone X',
description: 'Expedita sequi perferendis quod illum pariatur aliquam, alias laboriosam! Vero blanditiis placeat, mollitia necessitatibus reprehenderit. Labore dolores amet quos, accusamus earum asperiores officiis assumenda optio architecto quia neque, quae eum.'
},
],
user: {},
isSignedIn: false
};
},
view: {
pushState: true
},
// App routes
routes: routes,
// Register service worker
serviceWorker: {
path: '/service-worker.js',
},
};
Update root data user object in firebase.auth().onAuthStateChanged
var that = this;
that.$f7.data.isSignedIn = true;
that.$f7.data.user.displayName = currentUser.displayName;
that.$f7.data.user.photoURL = currentUser.photoURL;
that.$f7.data.user.phoneNumber = currentUser.phoneNumber;
that.$f7.data.user.nicNumber = userData.userNIC;
Then in any componentDidMount
authOnChange() {
// console.log('Home - authOnChange :: init');
if (this.$f7.data.isSignedIn == true) {
this.setState({
isSignedIn: true
});
// this.$f7.preloader.hide();
if (!this.$f7.data.user.tourGuide) {
this.setState({
run: true,
});
}
} else {
setTimeout(() => this.authOnChange(), 5000);
}
}
componentDidMount() {
// console.log('Home - componentDidMount :: init');
if (this.$f7.data.isSignedIn == false) {
this.authOnChange();
}
}
Hope this help!
Let us know if you’ve use any different approach.
Happy Coding!