Files
kottgard-production/src/presentation/hooks/useAuth.ts
T

25 lines
914 B
TypeScript

'use client';
import { Address, Order, User } from '@/domain/entities';
import { RegisterInput } from '@/domain/services/AuthDomainService';
import { container } from '@/application/container';
import { useAuthStore } from '@/infrastructure/persistence/zustand/authStore';
export function useAuth() {
const user = useAuthStore((s) => s.user);
const orders = useAuthStore((s) => s.orders);
const isAuthenticated = useAuthStore((s) => s.isAuthenticated);
return {
user,
orders,
isAuthenticated,
login: (email: string, password: string) =>
container.login.execute(email, password),
register: (data: RegisterInput) => container.register.execute(data),
logout: () => container.authRepository.logout(),
updateProfile: (data: Partial<User>) =>
container.authRepository.updateProfile(data),
addOrder: (order: Order) => container.authRepository.addOrder(order),
};
}