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
43 lines
1,021 B
TypeScript
43 lines
1,021 B
TypeScript
"use client";
|
|
|
|
import { createContext, useContext, ReactNode } from "react";
|
|
import { authClient, useSession } from "@/lib/auth-client";
|
|
|
|
type AuthContextType = {
|
|
session: ReturnType<typeof useSession>["data"];
|
|
isPending: boolean;
|
|
error: ReturnType<typeof useSession>["error"];
|
|
signOut: () => Promise<void>;
|
|
};
|
|
|
|
const AuthContext = createContext<AuthContextType | null>(null);
|
|
|
|
export function AuthProvider({ children }: { children: ReactNode }) {
|
|
const { data: session, isPending, error } = useSession();
|
|
|
|
const handleSignOut = async () => {
|
|
await authClient.signOut();
|
|
window.location.href = "/auth/sign-in";
|
|
};
|
|
|
|
return (
|
|
<AuthContext.Provider
|
|
value={{
|
|
session,
|
|
isPending,
|
|
error,
|
|
signOut: handleSignOut,
|
|
}}
|
|
>
|
|
{children}
|
|
</AuthContext.Provider>
|
|
);
|
|
}
|
|
|
|
export function useAuth() {
|
|
const context = useContext(AuthContext);
|
|
if (!context) {
|
|
throw new Error("useAuth must be used within an AuthProvider");
|
|
}
|
|
return context;
|
|
}
|