Full CRM rebuild with Next.js 15, TypeScript, Tailwind, Drizzle ORM, PostgreSQL, Redis, BullMQ, MinIO, and Socket.io. Includes 461 source files covering clients, berths, interests/pipeline, documents/EOI, expenses/invoices, email, notifications, dashboard, admin, and client portal. CI/CD via Gitea Actions with Docker builds. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
52 lines
1.3 KiB
TypeScript
52 lines
1.3 KiB
TypeScript
'use client';
|
|
|
|
import { useSession } from '@/lib/auth/client';
|
|
import type { AuthUser, AuthSession } from '@/types/auth';
|
|
|
|
interface UseAuthReturn {
|
|
user: AuthUser | null;
|
|
session: AuthSession | null;
|
|
isLoading: boolean;
|
|
isAuthenticated: boolean;
|
|
}
|
|
|
|
/**
|
|
* Hook that wraps Better Auth's useSession and exposes a typed user + session.
|
|
*/
|
|
export function useAuth(): UseAuthReturn {
|
|
const { data: session, isPending } = useSession();
|
|
|
|
const user: AuthUser | null = session?.user
|
|
? {
|
|
id: session.user.id,
|
|
email: session.user.email,
|
|
name: session.user.name,
|
|
image: session.user.image ?? null,
|
|
emailVerified: session.user.emailVerified,
|
|
createdAt: session.user.createdAt,
|
|
updatedAt: session.user.updatedAt,
|
|
}
|
|
: null;
|
|
|
|
const typedSession: AuthSession | null = session
|
|
? {
|
|
id: session.session.id,
|
|
userId: session.session.userId,
|
|
token: session.session.token,
|
|
expiresAt: session.session.expiresAt,
|
|
ipAddress: session.session.ipAddress ?? null,
|
|
userAgent: session.session.userAgent ?? null,
|
|
createdAt: session.session.createdAt,
|
|
updatedAt: session.session.updatedAt,
|
|
user,
|
|
}
|
|
: null;
|
|
|
|
return {
|
|
user,
|
|
session: typedSession,
|
|
isLoading: isPending,
|
|
isAuthenticated: !!user,
|
|
};
|
|
}
|