Skip to content

Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.

750 B
Raw Blame
import "server-only";
import { auth } from "@/auth";
import prisma from "@/lib/db";
import { CurrentUser } from "@/models/user.model";

export const getCurrentUser = async () => {
  const session = await auth();
  if (!session?.user?.id) return null;
  // A JWT carries no proof the row still exists. Replace the database and the
  // signed cookie points at nothing, which every ownership-scoped query reads
  // as "no data" rather than "not signed in".
  const exists = await prisma.user.findUnique({
    where: { id: session.user.id },
    select: { id: true },
  });
  if (!exists) return null;
  const user: CurrentUser = {
    id: session.user.id,
    name: session.user.name ?? "",
    email: session.user.email ?? "",
  };
  return user;
};