import { type Request, type Response, Router } from "express";
import { auth } from "../../../../pkg/auth/auth.js";

const router = Router();

router.patch("/:userId", async (req: Request, res: Response) => {
	const userId = req.params.userId;
	const cookieHeader = req.headers.cookie ?? "";
	const authorization = req.headers.authorization ?? "";

	const data = await auth.api.setUserPassword({
		body: {
			newPassword: req.body.password, // required
			userId: userId, // required
		},
		// This endpoint requires session cookies.
		headers: {
			cookie: cookieHeader,
			authorization,
		},
	});

	return res.status(200).json({ message: "Password was just changed." });
});
export default router;
