How to use @aws-amplify/cache - 6 common examples

To help you get started, we’ve selected a few @aws-amplify/cache 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 / Providers / AWSPinpointProvider.ts View on Github external
private async _getEndpointId(cacheKey) {
		// try to get from cache
		let endpointId = await Cache.getItem(cacheKey);
		logger.debug(
			'endpointId from cache',
			endpointId,
			'type',
			typeof endpointId
		);
		if (!endpointId) {
			endpointId = uuid();
			Cache.setItem(cacheKey, endpointId);
		}
		return endpointId;
	}
github aws-amplify / amplify-js / packages / analytics / src / Providers / AWSPinpointProvider.ts View on Github external
private async _getEndpointId(cacheKey) {
		// try to get from cache
		let endpointId = await Cache.getItem(cacheKey);
		logger.debug(
			'endpointId from cache',
			endpointId,
			'type',
			typeof endpointId
		);
		if (!endpointId) {
			endpointId = uuid();
			Cache.setItem(cacheKey, endpointId);
		}
		return endpointId;
	}
github TreeHacks / root / src / store / auth / actions.ts View on Github external
return dispatch => {
    loadingStart();
    console.log("signing out");
    Cache.removeItem("federatedInfo");
    localStorage.clear();
    Auth.signOut().then(e => {
      loadingEnd();
      dispatch(loggedOut());
    })
  }
}
github aws-amplify / amplify-js / packages / api-graphql / src / GraphQLAPI.ts View on Github external
if (!apiKey) {
					throw new Error('No api-key configured');
				}
				headers = {
					Authorization: null,
					'X-Api-Key': apiKey,
				};
				break;
			case 'AWS_IAM':
				const credentialsOK = await this._ensureCredentials();
				if (!credentialsOK) {
					throw new Error('No credentials');
				}
				break;
			case 'OPENID_CONNECT':
				const federatedInfo = await Cache.getItem('federatedInfo');

				if (!federatedInfo || !federatedInfo.token) {
					throw new Error('No federated jwt');
				}
				headers = {
					Authorization: federatedInfo.token,
				};
				break;
			case 'AMAZON_COGNITO_USER_POOLS':
				const session = await Auth.currentSession();
				headers = {
					Authorization: session.getAccessToken().getJwtToken(),
				};
				break;
			default:
				headers = {
github aws-amplify / amplify-js / packages / api / src / API.ts View on Github external
if (!apiKey) {
					throw new Error('No api-key configured');
				}
				headers = {
					Authorization: null,
					'X-Api-Key': apiKey,
				};
				break;
			case 'AWS_IAM':
				const credentialsOK = await this._ensureCredentials();
				if (!credentialsOK) {
					throw new Error('No credentials');
				}
				break;
			case 'OPENID_CONNECT':
				const federatedInfo = await Cache.getItem('federatedInfo');

				if (!federatedInfo || !federatedInfo.token) {
					throw new Error('No federated jwt');
				}
				headers = {
					Authorization: federatedInfo.token,
				};
				break;
			case 'AMAZON_COGNITO_USER_POOLS':
				const session = await Auth.currentSession();
				headers = {
					Authorization: session.getAccessToken().getJwtToken(),
				};
				break;
			default:
				headers = {
github aws-amplify / amplify-js / packages / api / src / API.ts View on Github external
} = this._options;
        let headers = {};

        switch (authenticationType) {
            case 'API_KEY':
                headers = {
                    Authorization: null,
                    'X-Api-Key': apiKey
                };
                break;
            case 'AWS_IAM':
                const credentialsOK = await this._ensureCredentials();
                if (!credentialsOK) { throw new Error('No credentials'); }
                break;
            case 'OPENID_CONNECT':
                const federatedInfo = await Cache.getItem('federatedInfo');

                if (!federatedInfo || !federatedInfo.token) { throw new Error('No federated jwt'); }
                headers = {
                    Authorization: federatedInfo.token
                };
                break;
            case 'AMAZON_COGNITO_USER_POOLS':
                if (Amplify.Auth && typeof Amplify.Auth.currentSession === 'function') {
                    const session = await Amplify.Auth.currentSession();
                    headers = {
                        Authorization: session.getAccessToken().getJwtToken()
                    };
                } else {
                    throw new Error('No Auth module registered in Amplify');
                }
                break;

@aws-amplify/cache

Cache category of aws-amplify

Apache-2.0
Latest version published 1 year ago

Package Health Score

78 / 100
Full package analysis

Similar packages