npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

amplify-redux-auth

v0.1.11

Published

React component wraps the AWS Amplify that holds auth state within Redux store.

Downloads

74

Readme

amplify-redux-auth

npm version License: MIT

  • Wraps the Amplify Authentication with Redux.
  • Uses Redux for state management, suitable if your application is using Amplify, Redux and react-redux, makes it easy to plugin the authentication state into your own global state.
  • Redux Actions exposed for you to manipulate the auth state freely.
  • BYO authentication component, you can choose your own authentication component or use the default.

Usage

yarn add aws-amplify amplify-redux-auth react react-dom react-redux @material-ui/core

Or

npm install --save aws-amplify amplify-redux-auth react react-dom react-redux @material-ui/core

Note: @material-ui/core is used by the library and required as Peer Dependencies (to avoid that if @material-ui/core is used in your application, it will have conflict), this may be changed in the future (remove it as peer dependency).

Note: AWS Amplify Rollup bundling issue, has to make it as peer dependencies.

Configure AWS Amplify from you application

import { configureAmplify } from 'amplify-redux-auth';

// You can supply AWS Amplify config in you index.ts or index.js just before ReactDOM.render.
// See https://aws-amplify.github.io/docs/js/authentication#manual-setup
const awsAmplifyConfig = {
  Auth: {
    region: process.env.REACT_APP_AWS_REGION,
    identityPoolId: process.env.REACT_APP_COGNITO_IDENTITY_ID,
    userPoolId: process.env.REACT_APP_COGNITO_USER_POOL_ID,
    userPoolWebClientId: process.env.REACT_APP_COGNITO_WEB_CLIENT_ID
  }
};

configureAmplify(awsAmplifyConfig);

ReactDOM.render(rootComponent(), document.getElementById('root'));

Hook up the state/sagas to your Redux store

// reducers.ts
import { combineReducers } from 'redux';
import { authState } from 'amplify-redux-auth';

export const rootReducer = combineReducers({
  authState,
  ... // your other reducers
});

// sagas.ts
import { sagaMiddleware } from './store';
import { authSagas } from 'amplify-redux-auth';

export const rootSaga = {
  run: () => sagaMiddleware.run(authSagas),
  .... // your other sagas
};

Wrap it with your component

import ....
import AmplifyReduxAuth, { logout, State, UserData } from 'amplify-redux-auth';

const App = ({ logout, user, loggedIn }) => (
  <AmplifyReduxAuth logoText={'My Logo'}>
    <div>
      You've logged in!
    </div>
  </AmplifyReduxAuth>
);

const mapStateToProps = (state: State) => ({
  user: state.authState.currentUser,
  loggedIn: state.authState.loggedIn
});

const mapDispatchToProps = (dispatch: Dispatch) => ({
  logout: bindActionCreators(logout, dispatch)
});

export default compose<AppProps, {}>(
  connect(mapStateToProps, mapDispatchToProps)
)(App);

Custom authentication component (see ../example folder).

<AmplifyReduxAuth AuthComponent={<YourCustomAuth />>
  ...
</AmplifyReduxAuth>

:shipit: :shipit: :shipit:

TODO

  • Remove bunch of DRY code.
  • Tests! :see_no_evil:
  • Sign up feature with default Sign up form.
  • Custom auth flow, e.g. OAuth, SAML.
  • Improve the auth state, or make it more flexible.
  • Remove @material-ui as peer dependency.