Skip to content

Commit af5b8f5

Browse files
committed
fix .currentUser logic - the initial event doesn't have authenticated flag
1 parent 2657136 commit af5b8f5

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

android/src/main/java/io/fullstack/firestack/FirestackAuth.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,8 +627,7 @@ private WritableMap getUserMap() {
627627
userMap.putString("uid", uid);
628628
userMap.putString("providerId", provider);
629629
userMap.putBoolean("emailVerified", verified);
630-
631-
630+
632631
if (name != null) {
633632
userMap.putString("name", name);
634633
}

lib/modules/auth.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,30 @@ export default class Auth extends Base {
1414
this.authenticated = false;
1515
this._user = null;
1616

17-
this.getCurrentUser().then(this._onAuthStateChanged.bind(this)).catch(() => {
17+
// start listening straight away
18+
// generally though the initial event fired will get ignored
19+
// but this is ok as we fake it with the getCurrentUser below
20+
FirestackAuth.listenForAuth();
21+
22+
this.getCurrentUser().then((u) => {
23+
const authResult = { authenticated: !!u };
24+
if (u) authResult.user = u;
25+
this._onAuthStateChanged(authResult);
26+
this._startListening();
27+
}).catch(() => {
28+
// todo check if error contains user disabled message maybe and add a disabled flag?
29+
this._onAuthStateChanged({ authenticated: false });
30+
this._startListening();
1831
});
32+
}
1933

20-
// always track auth changes internally so we can access them synchronously
34+
/**
35+
* Internal function begin listening for auth changes
36+
* only called after getting current user.
37+
* @private
38+
*/
39+
_startListening() {
2140
FirestackAuthEvt.addListener('listenForAuth', this._onAuthStateChanged.bind(this));
22-
FirestackAuth.listenForAuth();
2341
}
2442

2543
/**

0 commit comments

Comments
 (0)