You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Listen for changes in the users auth state (logging in and out).
9
+
Listen for changes in the users auth state (logging in and out). This method returns a unsubscribe function to stop listening to events. Always ensure you unsubscribe from the listener when no longer needed to prevent updates to components no longer in use.
12
10
13
11
```javascript
14
-
firestack.auth().onAuthStateChanged((evt) => {
15
-
// evt is the authentication event, it contains an `error` key for carrying the
16
-
// error message in case of an error and a `user` key upon successful authentication
17
-
if (!evt.authenticated) {
18
-
// There was an error or there is no user
19
-
console.error(evt.error)
20
-
} else {
21
-
// evt.user contains the user details
22
-
console.log('User details', evt.user);
23
-
}
24
-
})
25
-
.then(() =>console.log('Listening for authentication changes'))
26
-
```
12
+
classExampleextendsReact.Component {
27
13
28
-
#### offAuthStateChanged()
29
-
30
-
Remove the `onAuthStateChanged` listener.
31
-
This is important to release resources from our app when we don't need to hold on to the listener any longer.
0 commit comments