2022-11-12 20:19:27 -05:00
|
|
|
import { getCurrentUser } from "@lib/server/session"
|
2022-11-10 02:11:36 -05:00
|
|
|
import { NextApiRequest, NextApiResponse } from "next"
|
|
|
|
|
|
|
|
|
|
|
|
export default async function handler(
|
2022-11-12 20:19:27 -05:00
|
|
|
_: NextApiRequest,
|
2022-11-10 02:11:36 -05:00
|
|
|
res: NextApiResponse
|
|
|
|
): Promise<any> {
|
|
|
|
const error = () =>
|
|
|
|
res.status(401).json({
|
|
|
|
message: "Unauthorized"
|
|
|
|
})
|
|
|
|
try {
|
2022-11-12 20:19:27 -05:00
|
|
|
const user = await getCurrentUser()
|
2022-11-12 19:06:23 -05:00
|
|
|
|
2022-11-10 02:11:36 -05:00
|
|
|
if (!user) {
|
|
|
|
return error()
|
|
|
|
}
|
|
|
|
return res.json(user)
|
|
|
|
} catch (e) {
|
|
|
|
console.warn(`/api/user/self:`, e)
|
|
|
|
return error()
|
|
|
|
}
|
|
|
|
}
|