mirror of
https://github.com/umami-software/umami.git
synced 2026-02-14 01:25:37 +01:00
Renamed id routes for API.
This commit is contained in:
parent
53a991176b
commit
4429198397
42 changed files with 154 additions and 170 deletions
|
|
@ -12,10 +12,6 @@ import {
|
|||
import { getUser, updateUser } from 'queries';
|
||||
import * as yup from 'yup';
|
||||
|
||||
export interface UserPasswordRequestQuery {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export interface UserPasswordRequestBody {
|
||||
currentPassword: string;
|
||||
newPassword: string;
|
||||
|
|
@ -29,7 +25,7 @@ const schema = {
|
|||
};
|
||||
|
||||
export default async (
|
||||
req: NextApiRequestQueryBody<UserPasswordRequestQuery, UserPasswordRequestBody>,
|
||||
req: NextApiRequestQueryBody<any, UserPasswordRequestBody>,
|
||||
res: NextApiResponse<User>,
|
||||
) => {
|
||||
if (process.env.CLOUD_MODE) {
|
||||
|
|
@ -40,10 +36,10 @@ export default async (
|
|||
await useValidate(schema, req, res);
|
||||
|
||||
const { currentPassword, newPassword } = req.body;
|
||||
const { id } = req.auth.user;
|
||||
const { id: userId } = req.auth.user;
|
||||
|
||||
if (req.method === 'POST') {
|
||||
const user = await getUser(id, { includePassword: true });
|
||||
const user = await getUser(userId, { includePassword: true });
|
||||
|
||||
if (!checkPassword(currentPassword, user.password)) {
|
||||
return badRequest(res, 'Current password is incorrect');
|
||||
|
|
@ -51,7 +47,7 @@ export default async (
|
|||
|
||||
const password = hashPassword(newPassword);
|
||||
|
||||
const updated = await updateUser({ password }, { id });
|
||||
const updated = await updateUser(userId, { password });
|
||||
|
||||
return ok(res, updated);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue