use-wordpress-auth
v0.0.3
Published
React hooks for Wordpress authentication
Downloads
3
Readme
use-wordpress-auth
Made with create-react-library
Install
npm install --save use-wordpress-auth
Wrap your App
with the AuthProvider
in App.js
import React from 'react'
import { AuthProvider } from 'use-wordpress-auth'
const App = () => {
return <AuthProvider>{/* ... */}</AuthProvider>
}
Usage
import React from 'react'
import { useForm } from 'react-hook-form'
import { useAuth } from 'use-wordpress-auth'
const Example = () => {
const { handleSubmit, register, errors } = useForm()
const {
user,
loading,
isAuthenticated,
login,
signup,
isAuthenticating
} = useAuth()
if (isAuthenticated) {
return <div>Welcome {user.firstName}!</div>
}
return (
<form onSubmit={handleSubmit(login)}>
<label for='email'>Email</label>
<input type='email' name='email' ref={register} />
{errors.email && errors.email.message}
<label for='password'>Password</label>
<input type='password' name='password' ref={register} />
{errors.password && errors.password.message}
<button type='submit' disabled={loading}>
{loading ? 'Loading...' : 'Login'}
</button>
</form>
)
}
License
MIT © Moretape