Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

swiftcarrot/react-auth

Repository files navigation

@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

About

Authentication in React and React Native

Resources

Stars

Watchers

Forks

Packages

Contributors

AltStyle によって変換されたページ (->オリジナル) /