Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/seasonedcc/croods-auth

A ready-to-use solution for user authentication and permission control
https://github.com/seasonedcc/croods-auth

Last synced: about 1 month ago
JSON representation

A ready-to-use solution for user authentication and permission control

Awesome Lists containing this project

README

        

[![Maintainability](https://api.codeclimate.com/v1/badges/f37c434f6b6e73e2d050/maintainability)](https://codeclimate.com/github/SeasonedSoftware/croods-auth/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/f37c434f6b6e73e2d050/test_coverage)](https://codeclimate.com/github/SeasonedSoftware/croods-auth/test_coverage)
![npm bundle size](https://img.shields.io/bundlephobia/min/croods-auth)

# Croods-Auth

Croods-auth is another layer of abstraction on top of Croods, providing you with a ready-to-use solution for user authentication and permission control.

## Install

```bash
yarn add croods-auth croods react react-dom lodash react-use-form-state
```

## Usage

Bellow is a simple example of its usage with @reach/router:

```js
import { CroodsProvider } from 'croods'
import { Auth, authHeaders, saveHeaders } from 'croods-auth'

export default props => (


redirect('/sign-in')}
/>



)
```

Main concepts to notice here:

- **authHeaders:** Provides Croods with headers from the storage for usage on Croods requests. Eg.: Auth-Token, Uid, Client, Token-Type and Expiry.
- **Auth:** Used for checking permissions required for a component.

And then we implement our SignIn page:

```js
import { useSignIn } from 'croods-auth'

const Input = ({ name, label = name, ...props }) => (


{label}


)

export default props => {
const [{ signingIn, error, ...config }] = useSignIn({
afterSuccess: () => navigate(`/home`),
})
return (

Sign In





{signingIn ? 'Signing in...' : 'Sign in'}


)
}
```

There are hooks available for all usual authentication operations (sign up, edit profile, etc).

Read more about it [on the Docs](https://croods.netlify.com/docs/cauth-intro)!