feat(domain): complete phase 2 backend core

This commit is contained in:
poyrazavsever
2026-07-16 16:46:42 +03:00
parent 92bc99ba12
commit b155132acf
28 changed files with 5343 additions and 30 deletions
+24 -3
View File
@@ -1,13 +1,13 @@
import "server-only";
import { eq } from "drizzle-orm";
import { and, eq } from "drizzle-orm";
import { headers } from "next/headers";
import { redirect } from "next/navigation";
import { cache } from "react";
import { auth } from "@/server/auth/auth";
import type { UserRole } from "@/server/auth/types";
import { getSqliteConnection } from "@/server/db/client";
import { appProfiles } from "@/server/db/schema";
import { appProfiles, clients } from "@/server/db/schema";
type BetterAuthSession = NonNullable<Awaited<ReturnType<typeof auth.api.getSession>>>;
@@ -108,5 +108,26 @@ export function getProfileByAuthUserId(authUserId: string): SessionContext["prof
.limit(1)
.all();
return profile ?? null;
if (!profile) {
return null;
}
if (profile.role === "client") {
if (!profile.clientId) return null;
const linkedClient = db
.select({ id: clients.id })
.from(clients)
.where(
and(
eq(clients.id, profile.clientId),
eq(clients.authUserId, profile.authUserId),
),
)
.get();
if (!linkedClient) return null;
}
return profile;
}