Files
football-next/app/api/test-session/route.ts
2026-04-07 10:38:28 +03:30

30 lines
734 B
TypeScript

import { NextResponse } from "next/server";
import { getServerSession } from "next-auth";
import { authOptions } from "@/lib/auth";
import { db } from "@/lib/db";
export async function GET() {
const session = await getServerSession(authOptions);
if (!session) {
return NextResponse.json({ error: "No session" }, { status: 401 });
}
const userId = (session.user as any).id;
// بررسی وجود کاربر در دیتابیس
const user = await db.user.findUnique({
where: { id: userId },
select: { id: true, email: true, name: true, role: true }
});
return NextResponse.json({
session: {
user: session.user,
userId: userId,
},
userInDb: user,
exists: !!user
});
}