[auth][js] Add in `onUserChanged` method
This commit is contained in:
parent
e535a1ebaa
commit
9a17379e0e
|
@ -66,6 +66,7 @@ export default class Auth extends ModuleBase {
|
|||
_setAuthState(auth: AuthResultType) {
|
||||
this._authResult = auth;
|
||||
this._user = auth && auth.user ? new User(this, auth.user) : null;
|
||||
this.emit(this._getAppEventName('onUserChanged'), this._user);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -149,6 +150,26 @@ export default class Auth extends ModuleBase {
|
|||
this.removeListener(this._getAppEventName('onIdTokenChanged'), listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Listen for user changes.
|
||||
* @param listener
|
||||
*/
|
||||
onUserChanged(listener: Function) {
|
||||
this.log.info('Creating onUserChanged listener');
|
||||
this.on(this._getAppEventName('onUserChanged'), listener);
|
||||
if (this._authResult) listener(this._user || null);
|
||||
return this._offUserChanged.bind(this, listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove user change listener
|
||||
* @param listener
|
||||
*/
|
||||
_offUserChanged(listener: Function) {
|
||||
this.log.info('Removing onUserChanged listener');
|
||||
this.removeListener(this._getAppEventName('onUserChanged'), listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sign the current user out
|
||||
* @return {Promise}
|
||||
|
|
Loading…
Reference in New Issue