open-index/open-npm huggingface dataset:
npm package: @lohono/react-auth
Description: Authentication component for Lohono applications
Author: Isprava Developer
Latest version: 2.2.6

# @lohono/react-auth

A lightweight authentication component library for React applications.

## Installation

```bash
npm install @lohono/react-auth
```

## Features

- User session management
- User information handling
- TypeScript support
- Support for both CommonJS and ES Modules
- Lightweight with minimal dependencies

## Usage

### Using Session Hook

```typescript
import { useSession } from '@lohono/react-auth';

const AuthComponent = () => {
  const { session, isAuthenticated, updateSession, clearSession } = useSession();

  // Handle login
  const handleLogin = (token) => {
    updateSession(token);
  };

  // Handle logout
  const handleLogout = () => {
    clearSession();
  };

  return (
    <div>
      {isAuthenticated ? (
        <button onClick={handleLogout}>Logout</button>
      ) : (
        <button onClick={() => handleLogin("your-token")}>Login</button>
      )}
    </div>
  );
};
```

### Using User Info Hook

```typescript
import { useUserInfo } from '@lohono/react-auth';

const UserProfile = () => {
  const { userInfo, error, updateUserInfo, clearUserInfo } = useUserInfo();

  if (error) return <div>Error: {error.message}</div>;
  if (!userInfo) return <div>No user info found</div>;

  return (
    <div>
      <h1>Welcome, {userInfo.name}</h1>
      <p>Email: {userInfo.email}</p>
      <button onClick={clearUserInfo}>Clear Profile</button>
    </div>
  );
};
```

## API Reference

### useSession Hook

- `session`: Current session string
- `error`: Error object if any error occurs
- `updateSession(newSession: string)`: Update session
- `clearSession()`: Clear current session
- `isAuthenticated`: Boolean indicating if session exists

### useUserInfo Hook

- `userInfo`: Current user information object
- `error`: Error object if any error occurs
- `updateUserInfo(newUserInfo: UserInfo)`: Update user information
- `clearUserInfo()`: Clear user information

## Development

```bash
# Install dependencies
npm install

# Build the library
npm run build
```

## Requirements

- React 16.8.0 or higher
- React DOM 16.8.0 or higher

## License

MIT © Isprava Developer