Files
Homarr/src/pages/api/configs/tryPassword.tsx

42 lines
1.1 KiB
TypeScript
Raw Normal View History

import Consola from 'consola';
2022-06-06 17:13:17 +02:00
import { NextApiRequest, NextApiResponse } from 'next';
function Post(req: NextApiRequest, res: NextApiResponse) {
2023-03-21 11:35:07 +08:00
const { tried, type = 'password' } = req.body;
// If the type of password is "edit", we run this branch to check the edit password
if (type === 'edit') {
2023-09-03 17:54:12 +02:00
if (tried === process.env.EDIT_MODE_PASSWORD) {
if (process.env.DISABLE_EDIT_MODE?.toLowerCase() === 'true') {
process.env.DISABLE_EDIT_MODE = 'false';
} else {
process.env.DISABLE_EDIT_MODE = 'true';
}
2023-03-21 11:35:07 +08:00
return res.status(200).json({
success: true,
});
}
} else if (tried === process.env.PASSWORD) {
2022-06-06 17:13:17 +02:00
return res.status(200).json({
success: true,
});
}
Consola.warn(
2022-11-17 20:16:43 +09:00
`${new Date().toLocaleString()} : Wrong password attempt, from ${
req.headers['x-forwarded-for']
}`
);
2023-03-21 11:35:07 +08:00
return res.status(401).json({
2022-06-06 17:13:17 +02:00
success: false,
});
}
export default async (req: NextApiRequest, res: NextApiResponse) => {
if (req.method === 'POST') {
return Post(req, res);
}
return res.status(405).json({
statusCode: 405,
message: 'Method not allowed',
});
};