react-wordpress-auth

0.0.10 • Public • Published

react-wordpress-auth

Made with create-react-library

NPM JavaScript Style Guide

Install

npm install --save react-wordpress-auth

Wrap your App with the AuthProvider in App.js

import React from 'react'
import { AuthProvider } from 'react-wordpress-auth'
const App = () => {
  return <AuthProvider>{/* ... */}</AuthProvider>
}

Usage

import React from 'react'
import { useForm } from 'react-hook-form'
import { useAuth } from 'react-wordpress-auth'
 
const Login = () => {
  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

Readme

Keywords

none

Package Sidebar

Install

npm i react-wordpress-auth

Weekly Downloads

1

Version

0.0.10

License

MIT

Unpacked Size

95.3 kB

Total Files

6

Last publish

Collaborators

  • duongtanthao79
  • jonlovera