1.0.0-next.1 • Published 3 years ago

@ivyhjk/amplify-react-core-auth v1.0.0-next.1

Weekly downloads
39
License
MIT
Repository
github
Last release
3 years ago

React Amplify core authentication provider

React core authentication provider based on top of AWS Amplify

Install

with NPM:

npm install @ivyhjk/amplify-react-core-auth

with yarn:

yarn add @ivyhjk/amplify-react-core-auth

Usage

Put the context in your main application component:

import { CoreAuthContext } from '@ivyhjk/amplify-react-core-auth';

const App: React.Fc = () => (
  <CoreAuthContext>
    {/* ... */}
  </CoreAuthContext>
);

Hooks

Get the current authenticated user, directly from amplify, without cache:

import { useCurrentAuthenticatedUser } from '@ivyhjk/amplify-react-core-auth';

const UserComponent: React.FC = () => {
  const { error, loading, user } = useCurrentAuthenticatedUser();

  return (
    <p>
      Welcome {user.name}
    </p>
  );
}

Get the current authenticated user, from context (fastest):

import { useUser } from '@ivyhjk/amplify-react-core-auth';

const UserComponent: React.FC = () => {
  const user = useUser();

  return (
    <p>
      Welcome {user.name}
    </p>
  );
}