# wing-use-auth

> the auth hook for react app

Latest version **0.0.4** (published 2021-09-23) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install wing-use-auth
pnpm add wing-use-auth
yarn add wing-use-auth
bun add wing-use-auth
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2021-09-23 |
| First published | 2021-09-22 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 19.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Robben Wayley |
| Maintainers | wadlay |
| Keywords | auth, auth-hook, react, react hook |

## Links

- npm: https://www.npmjs.com/package/wing-use-auth
- Repository: https://github.com/Wayley/wing-use-auth
- Homepage: https://github.com/Wayley/wing-use-auth#readme
- Issues: https://github.com/Wayley/wing-use-auth/issues
- npm.io page: https://npm.io/package/wing-use-auth

## Dependencies (1)

- [react](https://npm.io/package/react.md) ^17.0.2

## Alternatives

- [@clerk/clerk-expo](https://npm.io/package/@clerk/clerk-expo.md) — 133.6K weekly downloads
- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads

## Recent versions

- 0.0.4 (latest) — 2021-09-23
- 0.0.3 — 2021-09-22
- 0.0.2 — 2021-09-22
- 0.0.1 — 2021-09-22

## README

# wing-use-auth

> The auth hook for react

## Install

```bash
$ yarn add wing-use-auth

# or

$ npm install wing-use-auth
```

## Import

```js
import useAuth, { AuthProvider } from "wing-use-auth";
```

## Usage

```js
// App.js

import { AuthProvider } from "wing-use-auth";

export default function App() {
  return (
    <AuthProvider options={{ cookieKey: "my-app-auth-key-name" }}>
      <ExamplePage />
    </AuthProvider>
  );
}
```

```js
// ExamplePage.js

import useAuth from "wing-use-auth";

function ExamplePage() {
  const auth = useAuth();
  const login = () => {
    auth.signin(() => {
      // do something here
      // such as: set storage/cookie
      console.log("Logged in");
    });
  };
  return (
    <div>
      {auth.authenticated ? (
        <h1>You have authenticated</h1>
      ) : (
        <div>
          You have not logged in yet，<button onClick={login}>Log In</button>
        </div>
      )}
    </div>
  );
}
```

### AuthProvider Options

|   Attribute    | Version |                                                                                                                 Remark                                                                                                                 |
| :------------: | :-----: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
| `initialState` | <=0.0.3 |                                                                             <div style="color: #fff; background: red; padding: 2px 10px">deprecated</div>                                                                              |
|  `cookieKey`   | >=0.0.4 | 根据 cookie 值来设置初识的状态<br><p style="font-size:14px;">(例如: 在登录的时候设置 cookie 的`key`为`my-app-auth-key-name`,那么在初始化状态的时候，会自动取读取该 cookie 值，如果 cookie 存储了该值，那么`authenticated`为`true`)</p> |

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