1.0.8 • Published 4 years ago

react-accessories v1.0.8

Weekly downloads
2
License
ISC
Repository
github
Last release
4 years ago

Project Title

A react accessories library for making CRUD restful call and handling authentication

Getting Started

no content yet

Installing

no content yet

Usage

import { AuthContextProvider, useAuthContext } from "react-accessory";

interface User {
  name: string;
  iat: number;
}
function Child() {
  const auth = useAuthContext<User>();
  const { handleTokenChange, userInfo, token, isLogined } = auth;
   return (
        <>
          <pre>{JSON.stringify(userInfo, null, 4)}</pre>
          <button onClick={() => handleTokenChange('')}>logout</button>
        </>
  );
}

function App() {
  return (
    <AuthContextProvider defaultUser={{ name: "", iat: -1 }}>
      <Child />
    </AuthContextProvider>
  );
}

Authentication

  • handleTokenChange: actively update token, can be used for logout
  • userInfo: decoded information inside token
  • isLogined: true if token is not empty

Built With

  • React - A JavaScript library for building user interfaces

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

  • Create based on this example
1.0.8

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago