0.1.81 • Published 6 months ago
react-starter-auth v0.1.81
Features
Authentication library built for react token based authentication with JWT
- Lightweight and easy to use
- Built for React JS
- Works with Next js
- JWT based authentication
- Secure client authentication
Installation
npm install react-starter-auth
yarn react-starter-auth
Setup
import { AuthProvider } from 'react-starter-auth';
<AuthProvider>
<App>
</AuthProvider>
Signin
import { useAuth } from 'react-starter-auth'
const { signIn } = useAuth()
const access_token = 'jsjdjdjsxxfd' // response from api
const user {
name: 'john doe',
email: 'example@example.com',
phone: '',
role: ''
}
const authuser = {
token: access_token,
user: user
}
signIn(authuser)
User
import { useAuth } from 'react-starter-auth'
const { isAuthenticated, user } = useAuth()
Fetcher
fetcher extends the native Web fetch() API to update each request on the server to set headers Authorizaton Bearer upon sign in.
import { fetcher } from 'react-starter-auth'
const res = fetcher('https://example.com/api/posts') // GET
const data = await res.json()
const res = fetcher('https://example.com/api/posts', { method: 'POST', body: JSON.stringify(data) }) // POST
const data = await res.json()
Private route page
import { ProtectedRoute, withAuthentication } from 'react-starter-auth'
0.1.81
6 months ago
0.1.8
6 months ago
0.1.7
6 months ago
0.1.6
6 months ago
0.1.5
6 months ago
0.1.4
6 months ago
0.1.3
6 months ago
0.1.2
6 months ago
0.1.1
6 months ago
0.1.0
6 months ago
0.0.9
6 months ago
0.0.8
6 months ago
0.0.6
6 months ago
0.0.5
6 months ago
0.0.4
6 months ago
0.0.3
6 months ago
0.0.2
6 months ago
0.0.1
6 months ago