Authentication in React and React Native
yarn add @swiftcarrot/react-auth
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>;
};
- getCurrentUser
- beforeLoginUser
- afterLoginUser
- beforeLogoutUser
- afterLogoutUser
- renderLoading
- renderLoading
- renderLogin
- loading
- setLoading
- currentUser
- setCurrentUser
- loginUser
- logoutUser
MIT