diff --git a/backend/src/main.ts b/backend/src/main.ts index 6133de2..8d9b250 100644 --- a/backend/src/main.ts +++ b/backend/src/main.ts @@ -11,11 +11,25 @@ async function bootstrap() { app.setGlobalPrefix('api'); + const allowedOrigins = [ + process.env.FRONTEND_URL, + 'http://localhost:3001', + 'http://127.0.0.1:3001', + 'http://localhost:8080', + 'http://127.0.0.1:8080', + ].filter(Boolean) as string[]; + app.enableCors({ - origin: process.env.NODE_ENV === 'production' - ? process.env.FRONTEND_URL - : true, + origin: (origin, callback) => { + if (!origin || allowedOrigins.includes(origin)) { + callback(null, true); + return; + } + callback(null, false); + }, credentials: true, + methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'], + allowedHeaders: ['Content-Type', 'Authorization', 'X-Tenant-Id'], }); app.useWebSocketAdapter(new WsAuthAdapter(app)); diff --git a/backend/tsconfig.json b/backend/tsconfig.json index 8d12c1f..095266c 100644 --- a/backend/tsconfig.json +++ b/backend/tsconfig.json @@ -1,19 +1,21 @@ -{ - "compilerOptions": { - "module": "nodenext", - "moduleResolution": "nodenext", - "resolvePackageJsonExports": true, - "esModuleInterop": true, - "isolatedModules": true, - "declaration": true, - "removeComments": true, - "emitDecoratorMetadata": true, - "experimentalDecorators": true, - "allowSyntheticDefaultImports": true, - "target": "ES2023", +{ + "compilerOptions": { + "module": "nodenext", + "moduleResolution": "nodenext", + "resolvePackageJsonExports": true, + "esModuleInterop": true, + "isolatedModules": true, + "declaration": true, + "removeComments": true, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "allowSyntheticDefaultImports": true, + "target": "ES2023", "sourceMap": true, + "rootDir": "./src", "outDir": "./dist", "baseUrl": "./", + "ignoreDeprecations": "6.0", "paths": { "src/*": ["src/*"], "@/*": ["src/*"] diff --git a/frontend/.env.example b/frontend/.env.example index 802e4d8..6cffbfe 100644 --- a/frontend/.env.example +++ b/frontend/.env.example @@ -1,3 +1,6 @@ -AUTH_SECRET={AUTH_SECRET} +AUTH_SECRET=XKZ7Z1O3bhU4caz2D8ouu7dKhXyQ+ZUhsjvTwtHxp10= +NEXTAUTH_SECRET=XKZ7Z1O3bhU4caz2D8ouu7dKhXyQ+ZUhsjvTwtHxp10= +AUTH_URL=http://localhost:3001 +NEXTAUTH_URL=http://localhost:3001 AUTH_GOOGLE_ID={AUTH_GOOGLE_ID} AUTH_GOOGLE_SECRET={AUTH_GOOGLE_SECRET} \ No newline at end of file diff --git a/frontend/src/app/dashboard/dashboard-content.tsx b/frontend/src/app/dashboard/dashboard-content.tsx new file mode 100644 index 0000000..59bb962 --- /dev/null +++ b/frontend/src/app/dashboard/dashboard-content.tsx @@ -0,0 +1,87 @@ +"use client"; + +import { CreatePostInput } from "@/components/dashboard/create-post-input"; +import { PostCard } from "@/components/dashboard/post-card"; +import { RightSidebar } from "@/components/dashboard/right-sidebar"; + +import { useActivityFeed } from "@/hooks/use-activity-feed"; +import { useCommunities } from "@/hooks/use-communities"; +import { useTenantContext } from "@/components/providers/tenant-provider"; +import { useSession } from "next-auth/react"; +import { useRouter, useSearchParams } from "next/navigation"; +import { useEffect } from "react"; + +export function DashboardContent() { + const { data: session } = useSession(); + const { communities, isLoading: communitiesLoading } = useCommunities(); + const { tenantId: currentTenantId, setTenantId } = useTenantContext(); + const router = useRouter(); + const searchParams = useSearchParams(); + const tenantIdFromUrl = searchParams.get("tenantId"); + + const { posts, isLoading, error, createPost, toggleLike, deletePost, editPost } = useActivityFeed(); + + useEffect(() => { + if (tenantIdFromUrl && tenantIdFromUrl !== currentTenantId) { + setTenantId(tenantIdFromUrl); + } + }, [tenantIdFromUrl, currentTenantId, setTenantId]); + + useEffect(() => { + if (!communitiesLoading && communities.length > 0 && !tenantIdFromUrl) { + const myCommunity = communities.find( + (c) => c.founderId === session?.user?.id || c.isMember + ); + + if (myCommunity) { + router.replace(`/dashboard?tenantId=${myCommunity.tenantId || myCommunity.id}`); + } + } + }, [communities, communitiesLoading, tenantIdFromUrl, router, session]); + + return ( +