diff --git a/lib/modules/auth/index.js b/lib/modules/auth/index.js index aa99ee76..675d0f07 100644 --- a/lib/modules/auth/index.js +++ b/lib/modules/auth/index.js @@ -37,6 +37,13 @@ export default class Auth extends ModuleBase { this._onAuthStateChanged.bind(this), ); + this.addListener( + // sub to internal native event - this fans out to + // public events based on event.type + this._getAppEventName('phone_auth_state_changed'), + this._onPhoneAuthStateChanged.bind(this), + ); + this.addListener( // sub to internal native event - this fans out to // public event name: onIdTokenChanged @@ -48,6 +55,16 @@ export default class Auth extends ModuleBase { this._native.addIdTokenListener(); } + /** + * Route a phone state change event to the correct listeners + * @param event + * @private + */ + _onPhoneAuthStateChanged(event: Object) { + const eventKey = `phone:auth:${event.requestKey}:${event.type}`; + this.emit(eventKey, event.state); + } + /** * Internal auth changed listener * @param auth @@ -102,7 +119,7 @@ export default class Auth extends ModuleBase { * Intercept all user actions and send their results to * auth state change before resolving * @param promise - * @returns {Promise.|*} + * @returns {Promise.<*>} * @private */ _interceptUserValue(promise) {