wulf-pulse/app/api/settings/profile/route.ts
root 9f912aed24 feat: add authentication, user management, and admin features
Added comprehensive authentication and authorization system:

Authentication System:
- Better Auth integration with session management
- Login/logout pages and API routes
- Middleware for route protection
- Auth utilities and client libraries

User Management:
- User list, detail, and invite pages
- User API endpoints (CRUD operations)
- Session management for users
- Profile settings page

Role-Based Access Control:
- Role management pages (list, create, edit)
- Permission system with granular controls
- Role assignment to users
- Role API endpoints

Admin Features:
- Audit log page for tracking system events
- Admin settings page
- Audit service for logging user actions

Additional Features:
- Quotes management pages and components
- SalesBldr API integration
- Email service for notifications

Configuration & Documentation:
- Updated docker-compose.yml
- MCP server configuration (mcp.json)
- CVE-2025-55182 security review documentation
- Standards guide and PRD documents
- Re-enabling authentication documentation

Database Migrations:
- 012: Auth tables (users, sessions, accounts, verifications)
- 013: Role tables (roles, permissions, role_permissions, user_roles)
- 014: Admin settings table

UI Updates:
- Updated dashboard layout
- Enhanced app layout with auth integration
2026-01-31 12:43:14 -05:00

39 lines
1 KiB
TypeScript

import { NextRequest, NextResponse } from "next/server";
import { Pool } from "pg";
import { requireAuth, getSession } from "@/lib/auth-utils";
const pool = new Pool({
connectionString: process.env.DATABASE_URL,
});
// PATCH /api/settings/profile - Update current user's profile
export async function PATCH(request: NextRequest) {
const { session, error } = await requireAuth();
if (error) return error;
try {
const body = await request.json();
const { name } = body;
if (!name) {
return NextResponse.json(
{ error: "Name is required" },
{ status: 400 }
);
}
const result = await pool.query(
`UPDATE "user" SET name = $1, updated_at = NOW() WHERE id = $2
RETURNING id, name, email`,
[name, session!.user.id]
);
return NextResponse.json({ user: result.rows[0] });
} catch (error) {
console.error("Error updating profile:", error);
return NextResponse.json(
{ error: "Failed to update profile" },
{ status: 500 }
);
}
}