I'm using Firebase and Expo to authenticate the user information by registering and logging in, when I log in or register no warnings show up, but when I sign out from the app it returns the warning: Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method. I narrowed down the problem to these three screens. I tried with many fixes with no results.
App.js
let unsubscribe;
export class App extends Component {
constructor(props) {
super(props);
this.state = {
loaded: false,
};
}
componentDidMount() {
unsubscribe = auth.onAuthStateChanged((user) => {
if (!user) {
this.setState({ loaded: true })
this.setState({ loggedIn: false })
} else {
this.setState({ loaded: true })
this.setState({ loggedIn: true })
}
})
}
componentWillUnmount() {
unsubscribe()
}
Account.js
export class Account extends React.Component {
constructor(props) {
super(props);
this.state = {
loaded: false,
signedIn: false,
modalVisible: false,
}
}
onSignOut = () => {
auth
.signOut()
}
Register.js
export class Register extends Component {
constructor(props) {
super(props);
this.state = {
email: '',
password: '',
phoneNumber: '',
loaded: false
}
}
componentDidMount() {
this.setState({loaded: true})
}
componentWillUnmount() {
this.signUp()
}
singUp = async () => {
const { phoneNumber, email, password } = this.state;
const number = '+1' + phoneNumber
try {
const phoneProvider = new PhoneAuthProvider(auth);
const verificationId = await phoneProvider.verifyPhoneNumber(
number,
recaptchaVerifier.current
);
this.props.navigation.navigate('VerifyPhoneNumber', {
verificationId: verificationId,
phoneNumber: number,
signInWithPhoneNumber: false,
email: email,
password: password
})
} catch (err) {
Alert.alert(
'Alert',
`${err}`
)
}
}