admin
This commit is contained in:
29
app/api/test-session/route.ts
Normal file
29
app/api/test-session/route.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
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
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user