import { User } from "@/interfaces/user";
import { IncomingMessage, ServerResponse } from "http";
import { IronSession } from "iron-session";
import { NextApiRequest, NextApiResponse } from "next";
import { getUser } from "./users.be";


export async function requestUser(req: NextApiRequest | IncomingMessage, res: NextApiResponse | ServerResponse): Promise<User | undefined> {
	if (!req.session.user) return undefined
	const user = await getUser(req.session.user.id)

	req.session.user = user
	req.session.save()

	return user
}
