Some checks failed
CI / Lint (push) Has been cancelled
CI / TypeCheck (push) Has been cancelled
CI / Test (push) Has been cancelled
Deploy / Docker Build & Push (map[context:. dockerfile:apps/api/Dockerfile name:api]) (push) Has been cancelled
Deploy / Docker Build & Push (map[context:. dockerfile:apps/cms/Dockerfile name:cms]) (push) Has been cancelled
Deploy / Docker Build & Push (map[context:. dockerfile:apps/web/Dockerfile name:web]) (push) Has been cancelled
CI / Build (push) Has been cancelled
Deploy / Deploy (push) Has been cancelled
- Monorepo: Turborepo + pnpm workspaces with 7 apps/packages - Backend: NestJS scaffold with 9 modules (auth, tenant, curriculum, simulation, portfolio, ai-coach, analytics, classroom, gamification) - Frontend: React 18 + Vite + TailwindCSS + shadcn/ui with 10 pages, 14 UI primitives, 3 Zustand stores - Database: Prisma schema with 19 models, 13 enums, seed script, multi-tenant ready - Docker: Dev, production, and Portainer Compose files with Traefik reverse proxy - Configuration: .env.example (47 vars), Zod validation, frontend-safe env exposure - i18n: English + Greek locale files (10 files), ICU MessageFormat, react-i18next - Shared packages: @investplay/types, @investplay/ui, @investplay/i18n, @investplay/utils - CI/CD: GitHub Actions (lint, typecheck, test, build, deploy, PR checks) - Documentation: CONTEXT.md, ARCHITECTURE.md (10 Mermaid diagrams), API.md, LOCALIZATION.md, DEVELOPMENT-ROADMAP.md - Infrastructure: Dockerfiles (dev + prod), nginx configs, backup/healthcheck scripts - Security: JWT auth guards, role-based access, rate limiting, Helmet, CORS, PII sanitization
54 lines
1.3 KiB
TypeScript
54 lines
1.3 KiB
TypeScript
import { useCallback } from "react";
|
|
import { useAuthStore } from "@/stores/auth.store";
|
|
import { setAuthTokens, clearAuthTokens } from "@/lib/api";
|
|
import { setGraphQLToken } from "@/lib/graphql";
|
|
import { disconnectSocket } from "@/lib/socket";
|
|
import type { User } from "@investplay/types";
|
|
|
|
export function useAuth() {
|
|
const store = useAuthStore();
|
|
|
|
const login = useCallback(
|
|
(user: User, accessToken: string, refreshToken: string) => {
|
|
setAuthTokens(accessToken, refreshToken);
|
|
setGraphQLToken(accessToken);
|
|
store.login(user, accessToken, refreshToken);
|
|
},
|
|
[store],
|
|
);
|
|
|
|
const register = useCallback(
|
|
(user: User, accessToken: string, refreshToken: string) => {
|
|
setAuthTokens(accessToken, refreshToken);
|
|
setGraphQLToken(accessToken);
|
|
store.register(user, accessToken, refreshToken);
|
|
},
|
|
[store],
|
|
);
|
|
|
|
const logout = useCallback(() => {
|
|
clearAuthTokens();
|
|
setGraphQLToken(null);
|
|
disconnectSocket();
|
|
store.logout();
|
|
}, [store]);
|
|
|
|
const updateUser = useCallback(
|
|
(partial: Partial<User>) => {
|
|
store.updateUser(partial);
|
|
},
|
|
[store],
|
|
);
|
|
|
|
return {
|
|
user: store.user,
|
|
accessToken: store.accessToken,
|
|
isAuthenticated: store.isAuthenticated,
|
|
isLoading: store.isLoading,
|
|
login,
|
|
register,
|
|
logout,
|
|
updateUser,
|
|
};
|
|
}
|