react-passport
- Client-side authentication for React
- React context for
client-passport
- Provides Hooks API
Installation
Instal react-passport
and client-passport
packages.
yarn add client-passport react-passport
Usage
First create an authenticator
instance.
;;; const authenticator = ;
Now use react-passport
to create React context.
;const Provider Consumer context useAuth = ;
Now you can use it as React context.
<Provider> <Consumer>loading user auth // ... </Consumer></Provider>
Where
loading
— is a boolean indicating whetherauthenticator
itself is loading.auth
— is the instance ofauthenticator
, you can use it for signing in/outauth.signIn('google')
andauth.signOut()
.user
— isnull
if user is not authenticated or an instance ofUser
object if user is authenticated. You can use it asuser.name
,user.avatar
,user.token
etc.
You can also use this library with React hooks.
const MyComponent = { const loading user auth = ; // ...};
License
Unlicense — public domain.