@swiftcarrot/react-auth

0.3.0 • Public • Published

@swiftcarrot/react-auth

npm npm Build Status codecov styled with prettier

Authentication in React and React Native

Installation

yarn add @swiftcarrot/react-auth

Usage

import React from 'react';
import { AuthProvider, AuthProtected, useAuth } from '@swiftcarrot/react-auth';

const getCurrentUser = () => fetch('/user');

const App = () => {
  return (
    <AuthProvider getCurrentUser={getCurrentUser}>
      <AuthProtected renderLoading={Loading} renderLogin={LoginPage}>
        <Dashboard />
      </AuthProtected>
    </AuthProvider>
  );
};

const Dashboard = () => {
  const { currentUser } = useAuth();
  return <div>{currentUser.name}</div>;
};

API

AuthProvider

  • getCurrentUser
  • beforeLoginUser
  • afterLoginUser
  • beforeLogoutUser
  • afterLogoutUser
  • renderLoading

AuthProtected

  • renderLoading
  • renderLogin

AuthContext

useAuth

Methods

  • loading
  • setLoading
  • currentUser
  • setCurrentUser
  • loginuser
  • logoutUser

License

MIT

Package Sidebar

Install

npm i @swiftcarrot/react-auth

Weekly Downloads

9

Version

0.3.0

License

MIT

Unpacked Size

11.5 kB

Total Files

4

Last publish

Collaborators

  • adjusted