mirror of
https://github.com/mudabbir-ahmad/peworkshop.git
synced 2026-10-08 03:50:21 +00:00
56 lines
1.2 KiB
JavaScript
56 lines
1.2 KiB
JavaScript
import { getServerSession } from "next-auth/next";
|
|
import { authOptions } from "../[...nextauth]/route";
|
|
|
|
export async function GET(req) {
|
|
try {
|
|
const session = await getServerSession(authOptions);
|
|
|
|
if (!session) {
|
|
return new Response(
|
|
JSON.stringify({
|
|
authenticated: false,
|
|
message: "Not authenticated",
|
|
}),
|
|
{
|
|
status: 401,
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
}
|
|
);
|
|
}
|
|
|
|
return new Response(
|
|
JSON.stringify({
|
|
authenticated: true,
|
|
user: {
|
|
id: session.user.id,
|
|
username: session.user.username,
|
|
role: session.user.role,
|
|
teamId: session.user.teamId,
|
|
},
|
|
}),
|
|
{
|
|
status: 200,
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
}
|
|
);
|
|
} catch (error) {
|
|
console.error("Session check error:", error);
|
|
|
|
return new Response(
|
|
JSON.stringify({
|
|
error: "Internal server error checking authentication",
|
|
}),
|
|
{
|
|
status: 500,
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
}
|
|
);
|
|
}
|
|
}
|