Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

808 B
Raw Blame
import { and, eq } from "drizzle-orm";
import db from "../../database";
import { accountTable, userTable } from "../../database/schema";
import { parseManagedProfileFields } from "../../utils/custom-oauth-env";

export async function getManagedProfile(userId: string) {
  const fields = parseManagedProfileFields();
  if (fields.length === 0) return null;

  const [stored] = await db
    .select({
      name: userTable.name,
      image: userTable.image,
      locale: userTable.locale,
    })
    .from(userTable)
    .innerJoin(
      accountTable,
      and(
        eq(accountTable.userId, userTable.id),
        eq(accountTable.providerId, "custom"),
      ),
    )
    .where(eq(userTable.id, userId))
    .limit(1);

  return stored ? { fields, stored } : null;
}

export default getManagedProfile;