Skip to content
This repository was archived by the owner on Apr 1, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Javascript Node CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#
version: 2
jobs:
build:
docker:
# specify the version you desire here
- image: circleci/node:7.10

# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
# - image: circleci/mongo:3.4.4

working_directory: ~/repo

steps:
- checkout

# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "package.json" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-

- run: yarn install

- save_cache:
paths:
- node_modules
key: v1-dependencies-{{ checksum "package.json" }}

# run tests!
- run: yarn test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ dist
*.sublime-workspace
path.sh
examples/config.json

.nyc_output
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# React Cognito

## Build status
![build status](https://circleci.com/gh/millarm/react-cognito.png?circle-token=80b20de573ee1b7ddab671889acaa6e2fa594623 "CircleCI build status")

You can now use Amazon Cognito to handle authentication and authorization for
your mobile and web applications. This is particularly useful for serverless
single-page applications (SPAs). SPAs can be hosted in S3 buckets and use AWS
Expand Down Expand Up @@ -62,4 +65,3 @@ User Pool. Contains no secret material.
#### config

The configuration provided by the application, used to contact Cognito.

119 changes: 119 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 19 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "react-cognito",
"scope": "winjer",
"version": "1.5.3",
"name": "react-cognito-mm",
"scope": "millarm",
"version": "1.6.15",
"description": "Use Amazon Cognito with React and Redux",
"main": "dist/react-cognito.js",
"repository": {
Expand All @@ -24,17 +24,16 @@
"scripts": {
"lint": "eslint ./src",
"lintfix": "eslint ./src --fix",
"testonly": "PWD=$(pwd) NODE_ENV=test mocha $npm_package_options_mocha || true",
"testonly": "PWD=$(pwd) NODE_ENV=test nyc --reporter=text mocha $npm_package_options_mocha || true",
"debug": "PWD=$(pwd) NODE_ENV=test mocha --debug-brk --inspect $npm_package_options_mocha",
"test": "npm run lint && npm run testonly",
"test-watch": "npm run testonly -- --watch --watch-extensions js",
"examples": "[ -d examples/htdocs/dist ] || mkdir examples/htdocs/dist; babel --plugins transform-es2015-modules-umd src --ignore __tests__ examples/src --out-file examples/htdocs/dist/bundle.js",
"doc": "esdoc",
"prepublish": "webpack -d; webpack -p"
"prepublish": "webpack -d; webpack -p",
"prepare": "webpack -d; webpack -p"
},
"devDependencies": {
"amazon-cognito-identity-js": "1.19.0",
"aws-sdk": "2.92.0",
"babel": "^6.5.2",
"babel-cli": "^6.18.0",
"babel-core": "^6.21.0",
Expand All @@ -45,7 +44,7 @@
"babel-polyfill": "^6.7.4",
"babel-preset-es2015": "^6.6.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-2": "^6.5.0",
"babel-preset-stage-2": "^6.24.1",
"chai": "^3.5.0",
"chai-as-promised": "^6.0.0",
"enzyme": "^2.2.0",
Expand All @@ -65,21 +64,26 @@
"local-web-server": "^1.2.6",
"mocha": "^3.2.0",
"nodemon": "^1.9.1",
"react": "^15.4.1",
"nyc": "^11.2.1",
"react-addons-test-utils": "^15.0.0",
"react-dom": "^15.0.0",
"react-redux": "^5.0.1",
"redux": "^3.6.0",
"sinon": "^2.2.0",
"sinon-chai": "^2.10.0",
"webpack": "^1.14.0",
"webpack-dev-server": "^1.16.2"
},
"peerDependencies": {
"react": "~0.14.8 || ^15.0.0",
"react-dom": "~0.14.8 || ^15.0.0"
"react": "~0.14.8 || ^15.0.0 || ^16.0.0",
"react-dom": "~0.14.8 || ^15.0.0 || ^16.0.0"
},
"dependencies": {
"babel-runtime": "^6.6.1"
"amazon-cognito-identity-js": "^3.0.11",
"aws-sdk": "^2.332.0",
"babel-runtime": "^6.6.1",
"flow": "^0.2.3",
"prop-types": "^15.6.0",
"react": "^15.4.1",
"react-dom": "^15.0.0",
"react-redux": "^5.0.6",
"redux": "^3.6.0"
}
}
25 changes: 13 additions & 12 deletions src/Logout.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import React, { PropTypes } from 'react';
/* eslint-disable react/prop-types */
import React from 'react';
import { Action } from './actions';

type Props = {
children: any,
onLogout: () => void,
};

type State = {
cognito: { user: { signOut: () => void } },
};

/**
* Container for logout behaviour.
* @example
* <Logout onLogout={handler}>
* <LogoutForm />
* </Logout>
*/
export class Logout extends React.Component {

export class Logout extends React.Component<Props, State> {
/**
* Passed to child element as onClick prop.
* Signs the user out, and then dispatches the logout action
Expand All @@ -23,7 +32,7 @@ export class Logout extends React.Component {
event.preventDefault();
store.dispatch(Action.logout());
this.props.onLogout();
}
};

/**
* renders the child element, adding an onClick property
Expand All @@ -34,14 +43,6 @@ export class Logout extends React.Component {
});
}
}
Logout.contextTypes = {
store: PropTypes.object,
};
Logout.propTypes = {
children: React.PropTypes.any.isRequired,
onLogout: React.PropTypes.func,
};
Logout.defaultProps = {
onLogout: () => {},
};

16 changes: 16 additions & 0 deletions src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ const Action = {
attributes,
}),

refresh: user => ({
type: 'COGNITO_REFRESH',
user,
}),

error: error => ({
type: 'COGNITO_ERROR',
error,
}),

logout: () => ({
type: 'COGNITO_LOGOUT',
}),
Expand All @@ -39,6 +49,12 @@ const Action = {
error,
}),

registerFailure: (userName, error) => ({
type: 'COGNITO_REGISTER_FAILURE',
userName,
error,
}),

mfaRequired: user => ({
type: 'COGNITO_LOGIN_MFA_REQUIRED',
user,
Expand Down
Loading