0.30.0 • Published 6 months ago

@spraoi/auth v0.30.0

Weekly downloads
9
License
MIT
Repository
github
Last release
6 months ago

@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 isnt 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 arent 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>
);
0.30.0

6 months ago

0.30.0-alpha.0

1 year ago

0.29.81

1 year ago

0.29.80

1 year ago

0.29.84

1 year ago

0.29.78

1 year ago

0.29.79

1 year ago

0.30.1-alpha.0

1 year ago

0.29.78-alpha.0

1 year ago

0.29.57

3 years ago

0.29.5

4 years ago

0.29.4

4 years ago

0.29.0

4 years ago

0.28.0

4 years ago

0.27.11

4 years ago

0.27.0

4 years ago

0.26.11

4 years ago

0.26.12

4 years ago

0.26.10

4 years ago

0.26.9

4 years ago

0.26.7

4 years ago

0.26.6

4 years ago

0.26.0

4 years ago

0.25.4

4 years ago

0.25.3

4 years ago

0.25.2

4 years ago

0.25.0

4 years ago

0.24.7

4 years ago

0.24.0

4 years ago

0.23.43

4 years ago

0.23.40

4 years ago

0.23.31

5 years ago

0.23.18

5 years ago

0.23.0

5 years ago

0.22.0

5 years ago

0.21.16

5 years ago

0.21.14

5 years ago

0.21.8

5 years ago

0.21.0

5 years ago

0.20.18

5 years ago

0.20.0

5 years ago

0.19.67

5 years ago

0.19.59

5 years ago

0.19.58

5 years ago

0.19.32

5 years ago

0.19.31

5 years ago

0.19.24

5 years ago

0.19.17

5 years ago

0.19.0

5 years ago

0.18.14

5 years ago

0.18.10

5 years ago

0.18.9

5 years ago

0.18.8

5 years ago

0.18.0

5 years ago

0.17.16

5 years ago

0.17.15

5 years ago

0.17.13

5 years ago

0.17.12

5 years ago

0.17.11

5 years ago

0.17.8

5 years ago

0.17.7

5 years ago

0.17.0

5 years ago

0.16.3

5 years ago

0.16.0

5 years ago

0.15.0

5 years ago

0.14.0

5 years ago

0.13.9

5 years ago

0.13.7

5 years ago

0.13.3

5 years ago