Initial commit
This commit is contained in:
27
app/api/auth/me/route.ts
Normal file
27
app/api/auth/me/route.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { ok } from "../../../../lib/http";
|
||||
import { getSession } from "../../../../lib/auth/session";
|
||||
import { getPrisma } from "../../../../lib/db";
|
||||
|
||||
export const runtime = "nodejs";
|
||||
|
||||
export async function GET() {
|
||||
const session = await getSession();
|
||||
if (!session) return ok({ session: null });
|
||||
|
||||
const prisma = await getPrisma();
|
||||
if (!prisma) return ok({ session });
|
||||
|
||||
const user = await prisma.user.findUnique({ where: { id: session.sub } });
|
||||
return ok({
|
||||
session,
|
||||
user: user
|
||||
? {
|
||||
firstName: user.firstName,
|
||||
lastName: user.lastName,
|
||||
avatarUrl: user.image,
|
||||
role: user.role,
|
||||
email: user.email,
|
||||
}
|
||||
: null,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user