# @spraoi/auth

> Container components for making authentication a breeze.

Latest version **0.30.0** (published 2023-11-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install @spraoi/auth
pnpm add @spraoi/auth
yarn add @spraoi/auth
bun add @spraoi/auth
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.30.0 |
| Published | 2023-11-22 |
| First published | 2018-11-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 11 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | kathani_p, kanchan1995, varunever, saidhruv, faizerestek, bhargav_everestek, bhargavk-everestek, narsiiiii, hiteshchaudhari-everestek |

## Links

- npm: https://www.npmjs.com/package/@spraoi/auth
- Repository: https://github.com/spraoi/common-ui
- Homepage: https://github.com/spraoi/common-ui/tree/master/packages/auth
- Issues: https://github.com/spraoi/common-ui/issues
- npm.io page: https://npm.io/package/@spraoi/auth

## Recent versions

- 0.30.0 (latest) — 2023-11-22
- 0.29.84 — 2023-01-17
- 0.29.81 — 2022-12-14
- 0.29.80 — 2022-12-14
- 0.29.79 — 2022-12-14
- 0.29.78 — 2022-12-14
- 0.29.78-alpha.0 — 2022-12-12
- 0.30.1-alpha.0 — 2022-12-12
- 0.30.0-alpha.0 — 2022-12-12
- 0.29.57 — 2021-05-17
- 0.29.5 — 2020-06-19
- 0.29.4 — 2020-06-17
- 0.29.0 — 2020-06-15
- 0.28.0 — 2020-06-15
- 0.27.11 — 2020-05-22
- … 54 more at https://npm.io/package/@spraoi/auth/versions

## README

# @spraoi/auth

> Container components for making authentication a breeze.

## Installation

```bash
yarn add @spraoi/auth
```

## Usage

### AuthProvider

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

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

const amplifyConfig = {
  // ...
};

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

#### Amplify Config Documentation

- https://aws-amplify.github.io/docs/js/authentication#manual-setup
- https://aws-amplify.github.io/docs/js/api#manual-setup
- https://aws-amplify.github.io/docs/js/storage#manual-setup

### AuthContext.Consumer

`AuthContext.Consumer` is just the
[context consumer](https://reactjs.org/docs/context.html#contextconsumer) for
the above `AuthProvider`.

```javascript
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&rsquo;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&rsquo;t shown until we know if the user is
authenticated or not.

#### Private Route Example

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

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

---
_Source: https://npm.io/package/@spraoi/auth · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
