JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 17
  • Score
    100M100P100Q75007F
  • License MIT

A CLI tool for sharing prompts, guides, and reusable systems across projects

Package Exports

  • aypackage
  • aypackage/bin/aypackage.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (aypackage) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

AyPackage - Better Auth System

A complete authentication system for Next.js applications using Better Auth.

🚀 Quick Start

Install the Better Auth system in your Next.js project:

npx aypackage systems better-auth

✨ Features

  • Complete Authentication System - Sign in, sign up, and session management
  • Role-Based Access Control - Admin, Editor, and User roles
  • Google OAuth Integration - Social authentication support
  • Beautiful UI Components - Pre-built signin/signup forms
  • TypeScript Support - Full type safety
  • App Router Compatible - Works with Next.js 13+ App Router

📁 What Gets Installed

Pages

  • /signin - Sign in page
  • /signup - Sign up page
  • /unauthorized - Unauthorized access page

API Routes

  • /api/auth/[...all] - Better Auth API handler

Components

  • AuthForm - Reusable authentication form component

Utilities

  • lib/auth.ts - Server-side auth configuration
  • lib/auth-client.ts - Client-side auth configuration
  • types/auth.ts - TypeScript definitions
  • hooks/queries.ts - Authentication hooks

🔧 Configuration

After installation, update your .env.local:

# Better Auth Configuration
BETTER_AUTH_SECRET=your-secret-key-here
BETTER_AUTH_URL=http://localhost:3000

# Google OAuth (optional)
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret

# Database
DATABASE_URL="postgresql://username:password@localhost:5432/database_name"
DIRECT_URL="postgresql://username:password@localhost:5432/database_name"

🛠 Usage

Server-Side Authentication

import { auth } from "@/lib/auth"
import { headers } from "next/headers"
import { redirect } from "next/navigation"

const session = await auth.api.getSession({
  headers: await headers()
})

if (!session || session.user.role !== 'ADMIN') {
  redirect('/unauthorized')
}

Client-Side Authentication

import { useAuth } from "@/hooks/queries"
import { isAdmin } from "@/types/auth"

const { session, user, isAuthenticated, isAdmin } = useAuth()

if (!isAuthenticated || !isAdmin) {
  router.push('/unauthorized')
}

Using the AuthForm Component

import { AuthForm } from "@/components/login-form"

// Sign in mode
<AuthForm mode="signin" />

// Sign up mode  
<AuthForm mode="signup" />

🔐 Security Features

  • Server-Side Validation - All routes protected with server-side checks
  • Role-Based Access - Admin, Editor, and User role support
  • Session Management - Secure session handling
  • CSRF Protection - Built-in CSRF protection
  • Rate Limiting - Protection against brute force attacks

📚 Documentation

For detailed documentation, see the Better Auth documentation.

🤝 Contributing

This package is part of the AyAutomate ecosystem. For contributions, please contact the development team.

📄 License

MIT License - see LICENSE file for details.