You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Portfolio/src/pages/api/user.ts

25 lines
553 B

import { NextApiHandler } from "next";
import { Response } from "@models/response";
import { methodNotAllowed, unauthorized } from "@utils/errors";
import { withIronSession } from "@utils/session";
const handler: NextApiHandler<Response> = (req, res) => {
if (req.method?.toUpperCase() !== "GET") {
res.status(405).json(methodNotAllowed);
return;
}
const user = req.session.user;
if (user === undefined) {
res.status(401).json(unauthorized);
return;
}
res.json({ ok: true, data: user });
};
export default withIronSession(handler);