GithubHelp home page GithubHelp logo

beeva-juanmanuelperez / aws-cognito-demo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from numo-labs/aws-cognito-demo

0.0 2.0 0.0 9 KB

:bust_in_silhouette: AWS Cognito demo

JavaScript 81.13% HTML 18.87%

aws-cognito-demo's Introduction

aws-cognito-demo

AWS Cognito demo

Amazon Cognito is a service that makes it easy to save user data in the AWS Cloud without writing any backend code or managing any infrastructure.

Run locally

Install the dependencies and start the webpack server

$ npm run init

Then open in the browser: http://localhost:3000/

You should expect to see a "Sign-in with Google" button:

cognito-google-login

Authorize the app

cognito-google-login-auth

Once authorized you should be re-directed back to the original page where you should see your Google profile:

cognito-google-authorised

What's inside

Initialize hello.js with Google ID

Hello.js — it is a client-side library that simplify authenticating.

  hello.init({
    google: '1007282893537-d12afmkgp97mjfa1plp7g4caginmkam9.apps.googleusercontent.com'
  }, {
    redirect_uri: window.location.href
  });

Add listener that triggered whenever a user logs in

  hello.on('auth.login', this.getUserInfo.bind(this));

Add listeners for the user login

Add listener, which will load a user profile into the page after they sign in.

  hello(auth.network).api('/me').then(user => {
    // set user data to the application state
  });

Set configuration for AWS

  AWS.config.region = 'eu-west-1';
  AWS.config.credentials = new AWS.CognitoIdentityCredentials({
    IdentityPoolId: 'eu-west-1:6c92ef81-d98a-4d97-8622-7274a5326309',
    Logins: {
      'accounts.google.com': auth.authResponse.id_token
    }
  });

Connect to AWS and get data from Cognito Cloud

  // get AWS credentials, so we can connect
  AWS.config.credentials.get(() => {
    // connect to cognito
    cognito.client = new AWS.CognitoSyncManager();

    // open or create new dataset
    cognito.client.openOrCreateDataset('DataSet', (err, dataset) => {
      cognito.dataSet = dataset;

      // get data from Cloud by the key
      dataset.get('DataKey', (err, data) => {
        // set data to the application state
      });

    });
  });

Put updated data to the Cognito Cloud

  cognito.dataSet.put('DataKey', 'DataValue', (err, record) => {
    // handler code here
  });

Libraries

aws-cognito-demo's People

Contributors

boyarskiy avatar nelsonic avatar jackcarlisle avatar s-voloshynenko avatar lilutanya avatar numo-labs-ci avatar

Watchers

James Cloos avatar Juan Manuel Pérez Rodríguez avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.