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
|
|
|
import { betterAuth } from "better-auth";
|
|
|
|
|
import { magicLink, twoFactor, admin } from "better-auth/plugins";
|
|
|
|
|
import { nextCookies } from "better-auth/next-js";
|
|
|
|
|
import { Pool } from "pg";
|
|
|
|
|
import { sendMagicLinkEmail } from "./services/email";
|
|
|
|
|
import { ac, adminRole, userRole, superAdminRole } from "./permissions";
|
|
|
|
|
|
|
|
|
|
// Create a PostgreSQL pool for Better Auth
|
|
|
|
|
const pool = new Pool({
|
|
|
|
|
connectionString: process.env.DATABASE_URL,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const auth = betterAuth({
|
|
|
|
|
database: pool,
|
|
|
|
|
appName: "Pulse",
|
|
|
|
|
baseURL: process.env.BETTER_AUTH_URL,
|
|
|
|
|
secret: process.env.BETTER_AUTH_SECRET,
|
|
|
|
|
trustedOrigins: [
|
|
|
|
|
"http://localhost:3100",
|
|
|
|
|
"https://pulse.wulfconsulting.cloud"
|
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
// Email & Password disabled - using magic link and Microsoft OAuth only
|
|
|
|
|
emailAndPassword: {
|
|
|
|
|
enabled: false,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// Session configuration
|
|
|
|
|
session: {
|
|
|
|
|
expiresIn: parseInt(process.env.SESSION_TIMEOUT_SECONDS || "86400"),
|
|
|
|
|
updateAge: 60 * 60, // Update session every hour
|
|
|
|
|
cookieCache: {
|
|
|
|
|
enabled: true,
|
|
|
|
|
maxAge: 5 * 60, // 5 minutes
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// Social providers
|
|
|
|
|
socialProviders: {
|
|
|
|
|
microsoft: {
|
|
|
|
|
clientId: process.env.MICROSOFT_CLIENT_ID || "",
|
|
|
|
|
clientSecret: process.env.MICROSOFT_CLIENT_SECRET || "",
|
|
|
|
|
tenantId: process.env.MICROSOFT_TENANT_ID || "common",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// Plugins
|
|
|
|
|
plugins: [
|
|
|
|
|
// Magic link authentication
|
|
|
|
|
magicLink({
|
|
|
|
|
sendMagicLink: async ({ email, url, token }) => {
|
|
|
|
|
await sendMagicLinkEmail({ email, url, token });
|
|
|
|
|
},
|
|
|
|
|
expiresIn: 300, // 5 minutes
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
// Two-factor authentication
|
|
|
|
|
twoFactor({
|
|
|
|
|
issuer: "Pulse",
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
// Admin plugin with RBAC
|
|
|
|
|
admin({
|
|
|
|
|
ac,
|
|
|
|
|
roles: {
|
|
|
|
|
"super-admin": superAdminRole,
|
|
|
|
|
admin: adminRole,
|
|
|
|
|
user: userRole,
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
// Next.js cookie handling - must be last
|
|
|
|
|
nextCookies(),
|
|
|
|
|
],
|
|
|
|
|
|
feat: add Autotask tags sync (tag groups, tags, ticket tag associations)
- Migration 057: autotask_tag_groups, autotask_tags, and junction tables
(ticket_tags, company_tags, configuration_item_tags, contact_tags)
- Add TAG_GROUPS and TAGS to EntityType enum and dependency map
- Add mapTagGroup() and mapTag() entity mapper functions
- Add syncTagGroups(), syncTags(), syncTicketTagAssociations() methods
- Wire TicketTagAssociations bulk sync into full/incremental sync flow
- Add 'exist' operator to QueryFilter type
- No FK on ticket_id (tagged tickets may be outside 2yr sync window)
Synced: 26 tag groups, 7299 tags, 10141 ticket-tag associations
2026-03-20 09:22:40 -04:00
|
|
|
// Allow Microsoft OAuth to link to existing accounts created by admins
|
|
|
|
|
account: {
|
|
|
|
|
accountLinking: {
|
|
|
|
|
enabled: true,
|
|
|
|
|
trustedProviders: ["microsoft"],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
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
|
|
|
// User configuration
|
|
|
|
|
user: {
|
|
|
|
|
additionalFields: {
|
|
|
|
|
role: {
|
|
|
|
|
type: "string",
|
|
|
|
|
defaultValue: "user",
|
|
|
|
|
},
|
|
|
|
|
requires_setup: {
|
|
|
|
|
type: "boolean",
|
|
|
|
|
defaultValue: false,
|
|
|
|
|
},
|
2026-05-07 07:36:35 -04:00
|
|
|
timezone: {
|
|
|
|
|
type: "string",
|
|
|
|
|
defaultValue: process.env.DEFAULT_TIMEZONE || "UTC",
|
|
|
|
|
},
|
2026-05-10 07:22:26 -04:00
|
|
|
theme: {
|
|
|
|
|
type: "string",
|
|
|
|
|
defaultValue: "system",
|
|
|
|
|
},
|
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
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export type Session = typeof auth.$Infer.Session;
|
|
|
|
|
export type User = typeof auth.$Infer.Session.user;
|