Code Monkey home page Code Monkey logo

ra-cognito's Introduction

ra-cognito

Authenticate a react admin CMS with cognito user pools.

Installation

With npm do:

npm install ra-cognito --save

Usage

ra-cognito provides a custom AuthProvider and login page for integration into a react-admin app. For example, in your main App.js:

import React from 'react';

import { Admin, Resource } from 'react-admin';
import simpleRestProvider from 'ra-data-simple-rest';
import { AuthProvider, Login } from 'ra-cognito';

import { PostList } from './posts';

const App = () => (
    <Admin
      authProvider={AuthProvider}
      dataProvider={simpleRestProvider('http://path.to.my.api')}
      loginPage={Login}
    >
        <Resource name="posts" list={PostList} />
    </Admin>
);

export default App;

The reason that ra-cognito exposes its own login page is because it is designed to handle the NEW_PASSWORD_REQUIRED authentication challenge from Cognito. A recently registered user may only access your resources once they have provided a new password. This is slightly different to the default react-admin authentication flow which assumes that a user is successfully authenticated at login time.

Custom login page styles

If you would like to provide custom styling for the login page, you may import the Login class without the Material UI styles, and then export this with your own styling:

import { withStyles } from '@material-ui/core/styles';
import { Login } from 'ra-cognito/dist/Login';
import pageStyles from './pageStyles';

export default withStyles(pageStyles)(Login);

And in ./pageStyles.js:

const pageStyles = theme => ({
  main: {
    display: 'flex',
    flexDirection: 'column',
    minHeight: '100vh',
    height: '1px',
    alignItems: 'center',
    justifyContent: 'flex-start',
    background:
      'linear-gradient(to top, hsla(210, 20%, 95%, 1), hsla(210, 20%, 90%, 1))',
    backgroundRepeat: 'no-repeat',
    backgroundSize: 'cover',
  },
  card: {
    minWidth: 300,
    marginTop: '6em',
  },
  avatar: {
    margin: '1em',
    display: 'flex',
    justifyContent: 'center',
  },
  icon: {
    backgroundColor: theme.palette.secondary[500],
  },
});

export default pageStyles;

License

MIT © The Distance

ra-cognito's People

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.