1.0.20 • Published 11 months ago

@antonvangoethem/cms v1.0.20

Weekly downloads
-
License
MIT
Repository
-
Last release
11 months ago

@antonvangoethem/cms

A shared CMS package for Next.js projects with built-in authentication, user management, and database utilities.

Features

  • 🔐 Authentication with JWT
  • 👥 User Management
  • 🗄️ Database utilities with Drizzle ORM
  • 🎨 Pre-built UI components

Installation

npm install @antonvangoethem/cms

Quick Start

  1. Set up your database connection in .env:
POSTGRES_URL=your_database_url
JWT_SECRET=your_secret_key
  1. Initialize the database:
// src/db/index.ts
import { createDb } from '@antonvangoethem/cms';
export const db = createDb();
  1. Set up authentication middleware:
// middleware.ts
import { createAuthMiddleware } from '@antonvangoethem/cms';

export const middleware = createAuthMiddleware(process.env.JWT_SECRET!, [
  '/auth/login',
  '/api/public'
]);
  1. Create authentication actions:
// src/app/actions/auth.ts
import { createAuthActions } from '@antonvangoethem/cms';
import { db } from '@/db';

const { login, logout } = createAuthActions(db, process.env.JWT_SECRET!);
export { login, logout };
  1. Use the login form component:
// src/app/auth/login/page.tsx
import { LoginForm } from '@antonvangoethem/cms';
import { login } from '@/app/actions/auth';

export default function LoginPage() {
  return (
    <div className="min-h-screen flex items-center justify-center">
      <LoginForm onSubmit={login} />
    </div>
  );
}
  1. Set up user management:
// src/app/actions/users.ts
import { createUserManagement } from '@antonvangoethem/cms';
import { db } from '@/db';

const { createUser, getUsers, updateUser, deleteUser } = createUserManagement(db);
export { createUser, getUsers, updateUser, deleteUser };

Components

LoginForm

A pre-built login form component with error handling and loading states.

<LoginForm 
  onSubmit={async (email, password) => {
    // Handle login
  }}
  error={error}
/>

UserTable

A pre-built user management table with edit and delete functionality.

<UserTable
  users={users}
  onDelete={async (id) => {
    // Handle delete
  }}
  onEdit={async (id, data) => {
    // Handle edit
  }}
/>

Database Schema

The package includes a pre-built users table schema:

export const usersTable = pgTable('users', {
  id: serial('id').primaryKey(),
  email: varchar('email', { length: 255 }).notNull().unique(),
  password: varchar('password', { length: 255 }).notNull(),
  name: varchar('name', { length: 255 }).notNull(),
  role: varchar('role', { length: 50 }).notNull().default('editor'),
  createdAt: timestamp('created_at').defaultNow().notNull(),
  updatedAt: timestamp('updated_at').defaultNow().notNull(),
});

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT

1.0.20

11 months ago

1.0.19

11 months ago

1.0.18

11 months ago

1.0.17

11 months ago

1.0.16

11 months ago

1.0.12

11 months ago

1.0.11

11 months ago

1.0.9

11 months ago

1.0.8

11 months ago

1.0.7

11 months ago