open-index/open-npm huggingface dataset:
npm package: @libreapps/auth
Description: Pluggable authentication library. Firebase support via @libreapps/auth-firebase (optional).
Author: LibreApps Contributors
Latest version: 3.0.1

# LibreApps Auth

## Initialization

Follow these steps to initialize authentication with LibreApps Auth for your project:

1. Install package with `pnpm i @libreapps/auth`

2. Create custom Header component that includes an `AuthWidget` from @libreapps/auth. See example in [luxdefi/sites repo](https://github.com/luxdefi/sites/tree/main/sites/credit/src/components/header)

3. Edit root layout component
``` typescript
// ... other imports

import { AuthServiceProvider } from '@libreapps/auth/service'
import { getUserServerSide } from '@libreapps/auth/server'
import type { AuthServiceConf } from '@libreapps/auth/types'

// custom header with AuthWidget
import Header from '@/components/header'

// ...other code

const RootLayout: React.FC<PropsWithChildren> = async ({
  children
}) =>  {
  const currentUser = await getUserServerSide()

  return (
    <AuthServiceProvider user={currentUser} conf={{} as AuthServiceConf}>
      <RootLayoutCommon siteDef={siteDef} header={false} >
        <Header siteDef={siteDef}/>
        {children}
      </RootLayoutCommon>
    </AuthServiceProvider>
  )
}
export default RootLayout
```

4. Create `/api/auth/login` route.
``` Typescript
import { NextRequest } from 'next/server'

import { handleLoginApiRequest } from '@libreapps/auth/server'

export async function POST(request: NextRequest) {
  return handleLoginApiRequest(request)
}
```

5. Create `/api/auth/logout` route.
``` Typescript
import { handleLogoutApiRequest } from '@libreapps/auth/server'

export async function GET() {
  return handleLogoutApiRequest()
}
```

6. Create `/login` route that uses `LoginComponent` from @libreapps/auth. See example in [luxdefi/sites repo](https://github.com/luxdefi/sites/tree/main/sites/credit/src/app/login)
npm package: @libreapps/auth-firebase
Description: Firebase authentication provider for @libreapps/auth
Author: LibreApps Contributors
Latest version: 1.1.1

# @libreapps/auth-firebase

Firebase authentication provider for `@libreapps/auth`.

## Installation

This package is **OPTIONAL**. Only install if you need Firebase authentication.

```bash
pnpm add @libreapps/auth-firebase firebase firebase-admin
```

## Usage

### Client-side Setup

Register the Firebase auth provider in your app's entry point:

```tsx
// app/providers.tsx or similar
import { FirebaseAuthService, isFirebaseConfigured } from '@libreapps/auth-firebase'
import { registerAuthProvider } from '@libreapps/auth'

// Register Firebase as the auth provider (only if configured)
if (isFirebaseConfigured()) {
  registerAuthProvider('firebase', FirebaseAuthService)
}
```

### Server-side Setup

For server-side authentication (Next.js Server Components, API routes):

```tsx
// In Server Components or API routes
import { getUserServerSide, createSessionCookie } from '@libreapps/auth-firebase/server'

// Get current user from session cookie
const user = await getUserServerSide()

// Create session cookie after login
const sessionCookie = await createSessionCookie(idToken, { expiresIn: 60 * 60 * 24 * 5 * 1000 })
```

## Environment Variables

### Client-side (NEXT_PUBLIC_*)

```env
NEXT_PUBLIC_FIREBASE_API_KEY=your-api-key
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=your-project.firebaseapp.com
NEXT_PUBLIC_FIREBASE_PROJECT_ID=your-project
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=your-project.appspot.com
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=123456789
NEXT_PUBLIC_FIREBASE_APP_ID=1:123456789:web:abcdef
```

### Server-side (Firebase Admin)

```env
FIREBASE_PROJECT_ID=your-project
FIREBASE_CLIENT_EMAIL=firebase-adminsdk-xxx@your-project.iam.gserviceaccount.com
FIREBASE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n"
```

## Without Firebase

If you don't need Firebase, simply don't install this package. The `@libreapps/auth` package works without Firebase - it will use a stub implementation that returns graceful failures for all auth operations.

## Exports

### Main (`@libreapps/auth-firebase`)

- `FirebaseAuthService` - The Firebase auth service implementation
- `isFirebaseConfigured()` - Check if Firebase client config is present

### Server (`@libreapps/auth-firebase/server`)

- `getUserServerSide()` - Get current user from session cookie
- `generateCustomToken()` - Generate a custom token
- `createSessionCookie()` - Create a session cookie from ID token
- `revokeAllSessions()` - Revoke all sessions for current user
- `isFirebaseAdminConfigured()` - Check if Firebase Admin is configured

### Service (`@libreapps/auth-firebase/service`)

- Low-level Firebase auth functions (for advanced use)