@spraoi/auth

0.30.0 • Public • Published

@spraoi/auth

Container components for making authentication a breeze.

Installation

yarn add @spraoi/auth

Usage

AuthProvider

AuthProvider is a container component that provides context to its children. Check the source for details.

import React from 'react';
import { AuthProvider } from '@spraoi/auth';

const amplifyConfig = {
  // ...
};

const AuthenticatedApp = (
  <AuthProvider amplifyConfig={amplifyConfig}>
    {/* your app goes here... */}
  </AuthProvider>
);

Amplify Config Documentation

AuthContext.Consumer

AuthContext.Consumer is just the context consumer for the above AuthProvider.

import React from 'react';
import { AuthContext } from '@spraoi/auth';

const Component = (
  <AuthContext.Consumer>
    {(authContext) => {
      // use the context here...
    }}
  </AuthContext.Consumer>
);

Page

Page is a simple authenticated/unauthenticated route container component/helper.

Props

isPrivate: bool

If true and the user isn’t authenticated, they are redirected to the login page or the redirect path. The current pathname is set to the redirect query param. This is useful for redirecting back to the page that was originally requested (once authenticated).

isPublic: bool

If true and the user is authenticated, they are redirected to the home page or the redirect path.

redirect: string

The path to redirect to in the cases above.

renderLoading: node

The component to render if waitForAuth is true.

waitForAuth: bool

If true, the page contents aren’t shown until we know if the user is authenticated or not.

Private Route Example

import React from 'react';
import { Page } from '@spraoi/auth';

const Route = (
  <Page isPrivate renderLoading="Loading!" waitForAuth>
    {/* your page goes here... */}
  </Page>
);

Readme

Keywords

none

Package Sidebar

Install

npm i @spraoi/auth

Weekly Downloads

62

Version

0.30.0

License

MIT

Unpacked Size

11.2 kB

Total Files

10

Last publish

Collaborators

  • kathani_p
  • kanchan1995
  • varunever
  • saidhruv
  • faizerestek
  • bhargav_everestek
  • bhargavk-everestek
  • narsiiiii
  • hiteshchaudhari-everestek