# @thedaviddias/auth
A comprehensive authentication package built for Next.js applications using Clerk as the authentication provider. This package provides a complete authentication solution with both server and client-side utilities, React components, and request-proxy support.
## Features
- 🔐 Complete Clerk authentication integration
- ⚡️ Server and client-side utilities
- 🎣 Type-safe React hooks for authentication state
- 🧩 Pre-built authentication components
- 🛡️ Strict type safety with TypeScript
- 🔄 Next.js proxy support
- 🔒 Built-in error handling
- 🎭 Fallback provider for testing and development
## Installation
```bash
pnpm add @thedaviddias/auth
```
## Prerequisites
This package requires the following peer dependencies:
- Next.js 15.x
- React 19.x
- Clerk project and credentials
You'll need to set up your Clerk environment variables:
```env
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=your-publishable-key
CLERK_SECRET_KEY=[credential removed]
```
## Usage
### 1. Provider Setup
Wrap your application with the AuthProvider:
```tsx
import { AuthProviderComponent } from '@thedaviddias/auth'
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
{children}
)
}
```
### 2. Client-Side Authentication
Use the provided hooks for client-side authentication:
```tsx
import { useAuth, useUser } from '@thedaviddias/auth'
export function AuthenticationExample() {
const { signOut, isLoaded } = useAuth()
const { user } = useUser()
if (!isLoaded) {
return
Loading...
}
if (!user) {
return
}
return (
Welcome, {user.email}
)
}
```
### 3. Server-Side Authentication
Access authentication state in server components:
```tsx
import { auth, currentUser } from '@thedaviddias/auth'
export default async function ServerComponent() {
const session = await auth()
const user = await currentUser()
if (!user) {
return