CoastalCommitsPastes/client/pages/api/user/self.ts
2022-11-12 17:19:27 -08:00

24 lines
468 B
TypeScript

import { getCurrentUser } from "@lib/server/session"
import { NextApiRequest, NextApiResponse } from "next"
export default async function handler(
_: NextApiRequest,
res: NextApiResponse
): Promise<any> {
const error = () =>
res.status(401).json({
message: "Unauthorized"
})
try {
const user = await getCurrentUser()
if (!user) {
return error()
}
return res.json(user)
} catch (e) {
console.warn(`/api/user/self:`, e)
return error()
}
}