2.0.8 • Published 2 years ago
@apiable/react-curity v2.0.8
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.0.8"
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()
2.0.8
2 years ago