amplify-redux-auth
- 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
; // 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-setupconst awsAmplifyConfig = Auth: region: processenvREACT_APP_AWS_REGION identityPoolId: processenvREACT_APP_COGNITO_IDENTITY_ID userPoolId: processenvREACT_APP_COGNITO_USER_POOL_ID userPoolWebClientId: processenvREACT_APP_COGNITO_WEB_CLIENT_ID ; ; ReactDOM;
Hook up the state/sagas to your Redux store
// reducers.ts;; const rootReducer = ; // sagas.ts;; const rootSaga = sagaMiddleware ... // your other sagas;
Wrap it with your component
; const App = <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);
../example folder).
Custom authentication component (see<AmplifyReduxAuth AuthComponent=<YourCustomAuth />> ...</AmplifyReduxAuth>
:shipit: :shipit: :shipit:
TODO
- Remove bunch of DRY code.
- Tests! 🙈
- 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.