use-wordpress-auth

0.0.3 • Public • Published

use-wordpress-auth

Made with create-react-library

NPM JavaScript Style Guide

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

Readme

Keywords

none

Package Sidebar

Install

npm i use-wordpress-auth

Weekly Downloads

0

Version

0.0.3

License

MIT

Unpacked Size

93.3 kB

Total Files

6

Last publish

Collaborators

  • duongtanthao79
  • jonlovera
  • jonlov