react-curity
TypeScript icon, indicating that this package has built-in type declarations

2.2.12 • Public • Published

Get started

A library using the plain vanilla javascript @curity/oauth-assistant library and adds React Context and hooks on top of it.

Import library with desired version

"react-curity": "^2.2.12"

Create a useAuth context file

e.g. under 'hooks/useAuth.ts' with following content

import {useContext} from 'react'
import {AuthContext, AuthContextValue} from 'react-curity'

const useAuth = () => useContext<AuthContextValue>(AuthContext as any)

export default useAuth

Add AuthProvider into yout index.tsx as App parent

import {AuthProvider} from 'react-curity'

<AuthProvider curityConfig={AUTH} fetchMe={() => API.get(`${API_URL}/users/me`)}>
  <App />
</AuthProvider>

Use the hooks in your components

const { loginWithRedirect, registerWithRedirect, logout, user, isAuthenticated } = useAuth()

Package Sidebar

Install

npm i react-curity

Weekly Downloads

8

Version

2.2.12

License

ISC

Unpacked Size

32.7 kB

Total Files

10

Last publish

Collaborators

  • apiable-peter
  • alex42