How to use the @aws-amplify/core.Hub.listen function in @aws-amplify/core

To help you get started, we’ve selected a few @aws-amplify/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aws-amplify / amplify-js / packages / analytics / src / index.ts View on Github external
};

const sendEvents = () => {
    const config = Analytics.configure();
    if (!endpointUpdated && config['autoSessionRecord']) {
        Analytics.updateEndpoint({ immediate: true }).catch(e => {
            logger.debug('Failed to update the endpoint', e);
        });
        endpointUpdated = true;
    }
    Analytics.autoTrack('session', {
        enable: config['autoSessionRecord']
    });
};

Hub.listen('auth', listener);
Hub.listen('storage', listener);
Hub.listen('analytics', listener);
github aws-amplify / amplify-js / packages / aws-amplify-react / src / Auth / SignOut.jsx View on Github external
constructor(props) {
        super(props);

        this.signOut = this.signOut.bind(this);
        Hub.listen('auth', this)
        this.onHubCapsule = this.onHubCapsule.bind(this)
        this.state = {};
    }
github aws-amplify / amplify-js / packages / aws-amplify-angular / src / providers / auth.decorator.ts View on Github external
function listen(authState: Subject) {
	const config = Amplify.configure(null);
	if (_.has(config, 'Auth.oauth')) {
		Hub.listen(
			'auth',
			{
				onHubCapsule: capsule => {
					const { channel, payload } = capsule;
					if (channel === 'auth') {
						const { username } = payload.data;
						logger.debug('authentication oauth event', payload);
						authState.next({ state: payload.event, user: { username } });
					}
				},
			},
			'angularAuthListener'
		);
	}
}
github aws-amplify / amplify-js / packages / analytics / src / index.ts View on Github external
const sendEvents = () => {
    const config = Analytics.configure();
    if (!endpointUpdated && config['autoSessionRecord']) {
        Analytics.updateEndpoint({ immediate: true }).catch(e => {
            logger.debug('Failed to update the endpoint', e);
        });
        endpointUpdated = true;
    }
    Analytics.autoTrack('session', {
        enable: config['autoSessionRecord']
    });
};

Hub.listen('auth', listener);
Hub.listen('storage', listener);
Hub.listen('analytics', listener);
github aws-amplify / amplify-js / packages / aws-amplify-react / src / Auth / Authenticator.jsx View on Github external
constructor(props) {
        super(props);

        this.handleStateChange = this.handleStateChange.bind(this);
        this.handleAuthEvent = this.handleAuthEvent.bind(this);
        this.onHubCapsule = this.onHubCapsule.bind(this);

        this._initialAuthState = this.props.authState || 'signIn';
        this.state = { authState: 'loading' };
        Hub.listen('auth', this);
    }
github aws-amplify / amplify-js / packages / analytics / src / index.ts View on Github external
const sendEvents = () => {
    const config = Analytics.configure();
    if (!endpointUpdated && config['autoSessionRecord']) {
        Analytics.updateEndpoint({ immediate: true }).catch(e => {
            logger.debug('Failed to update the endpoint', e);
        });
        endpointUpdated = true;
    }
    Analytics.autoTrack('session', {
        enable: config['autoSessionRecord']
    });
};

Hub.listen('auth', listener);
Hub.listen('storage', listener);
Hub.listen('analytics', listener);
github aws-amplify / amplify-js / packages / analytics / src / index.ts View on Github external
};

const sendEvents = () => {
	const config = Analytics.configure();
	if (!endpointUpdated && config['autoSessionRecord']) {
		Analytics.updateEndpoint({ immediate: true }).catch(e => {
			logger.debug('Failed to update the endpoint', e);
		});
		endpointUpdated = true;
	}
	Analytics.autoTrack('session', {
		enable: config['autoSessionRecord'],
	});
};

Hub.listen('auth', listener);
Hub.listen('storage', listener);
Hub.listen('analytics', listener);
github aws-amplify / amplify-js / packages / aws-amplify-react / src / Storage / S3Album.js View on Github external
constructor(props) {
        super(props);

        this.handlePick = this.handlePick.bind(this);
        this.handleClick = this.handleClick.bind(this);
        this.list = this.list.bind(this);
        this.marshal = this.marshal.bind(this);

        const theme = this.props.theme || AmplifyTheme;
        this.state = {
            theme,
            items: [],
            ts: new Date().getTime()
        };

        Hub.listen('window', this, 'S3Album');
    }
github aws-amplify / amplify-js / packages / aws-amplify-react / src / Auth / Authenticator.tsx View on Github external
constructor(props) {
		super(props);

		this.handleStateChange = this.handleStateChange.bind(this);
		this.handleAuthEvent = this.handleAuthEvent.bind(this);
		this.onHubCapsule = this.onHubCapsule.bind(this);

		this._initialAuthState = this.props.authState || 'signIn';
		this.state = { authState: 'loading' };
		Hub.listen('auth', this.onHubCapsule);
	}