Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 1e236d2

Browse files
author
jpaagt
committed
Added docs for authStateListener
1 parent d5cdf14 commit 1e236d2

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

README.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,50 @@ but if you only want to wipe everything at '/users', do this:
223223
```
224224

225225
### login
226-
v 1.1.0 of this plugin adds the capability to log your users in. Either anonymously or by email and password.
226+
v 1.1.0 of this plugin adds the capability to log your users in, either
227+
228+
* anonymously,
229+
230+
* by email and password or
231+
232+
* using a custom token.
233+
227234
You need to add support for those features in your Firebase instance at the 'Login & Auth' tab.
228235

229236
You can expect more login mechanisms to be added in the future.
230237

238+
#### Listening to auth state changes
239+
As stated [here](https://firebase.google.com/docs/auth/ios/manage-users#get_the_currently_signed-in_user)
240+
241+
> The recommended way to get the current user is by setting a listener on the Auth object
242+
243+
To listen to auth state changes you can register a listener like this:
244+
245+
```js
246+
var listener = {
247+
onAuthStateChanged: function(data) {
248+
console.log(data.loggedIn ? "Logged in to firebase" : "Logged out from firebase");
249+
if (data.loggedIn) {
250+
console.log("User info", data.user);
251+
}
252+
},
253+
thisArg: this
254+
};
255+
256+
firebase.addAuthStateListener(listener);
257+
```
258+
259+
To stop listening to auth state changed:
260+
261+
```js
262+
firebase.removeAuthStateListener(listener);
263+
```
264+
265+
To check if already listening to auth state changes
266+
```js
267+
firebase.removeAuthStateListener(listener);
268+
```
269+
231270
#### Anonymous login
232271
```js
233272
firebase.login({

0 commit comments

Comments
 (0)