mirror of
https://github.com/umami-software/umami.git
synced 2026-02-07 14:17:13 +01:00
Converted admin, auth, me and realtime routes.
This commit is contained in:
parent
6c9f1ad06b
commit
5205551ca8
25 changed files with 346 additions and 7 deletions
33
src/app/api/me/password/route.ts
Normal file
33
src/app/api/me/password/route.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import { z } from 'zod';
|
||||
import { parseRequest } from 'lib/request';
|
||||
import { json, badRequest } from 'lib/response';
|
||||
import { getUser, updateUser } from 'queries/prisma/user';
|
||||
import { checkPassword, hashPassword } from 'next-basics';
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const schema = z.object({
|
||||
currentPassword: z.string(),
|
||||
newPassword: z.string().min(8),
|
||||
});
|
||||
|
||||
const { auth, body, error } = await parseRequest(request, schema);
|
||||
|
||||
if (error) {
|
||||
return error();
|
||||
}
|
||||
|
||||
const userId = auth.user.id;
|
||||
const { currentPassword, newPassword } = body;
|
||||
|
||||
const user = await getUser(userId, { includePassword: true });
|
||||
|
||||
if (!checkPassword(currentPassword, user.password)) {
|
||||
return badRequest('Current password is incorrect');
|
||||
}
|
||||
|
||||
const password = hashPassword(newPassword);
|
||||
|
||||
const updated = await updateUser(userId, { password });
|
||||
|
||||
return json(updated);
|
||||
}
|
||||
12
src/app/api/me/route.ts
Normal file
12
src/app/api/me/route.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import { parseRequest } from 'lib/request';
|
||||
import { json } from 'lib/response';
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const { auth, error } = await parseRequest(request);
|
||||
|
||||
if (error) {
|
||||
return error();
|
||||
}
|
||||
|
||||
return json(auth);
|
||||
}
|
||||
21
src/app/api/me/teams/route.ts
Normal file
21
src/app/api/me/teams/route.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import { z } from 'zod';
|
||||
import { pagingParams } from 'lib/schema';
|
||||
import { getUserTeams } from 'queries';
|
||||
import { json } from 'lib/response';
|
||||
import { parseRequest } from 'lib/request';
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const schema = z.object({
|
||||
...pagingParams,
|
||||
});
|
||||
|
||||
const { auth, query, error } = await parseRequest(request, schema);
|
||||
|
||||
if (error) {
|
||||
return error();
|
||||
}
|
||||
|
||||
const teams = await getUserTeams(auth.user.id, query);
|
||||
|
||||
return json(teams);
|
||||
}
|
||||
21
src/app/api/me/websites/route.ts
Normal file
21
src/app/api/me/websites/route.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import { z } from 'zod';
|
||||
import { pagingParams } from 'lib/schema';
|
||||
import { getUserWebsites } from 'queries';
|
||||
import { json } from 'lib/response';
|
||||
import { parseRequest } from 'lib/request';
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const schema = z.object({
|
||||
...pagingParams,
|
||||
});
|
||||
|
||||
const { auth, query, error } = await parseRequest(request, schema);
|
||||
|
||||
if (error) {
|
||||
return error();
|
||||
}
|
||||
|
||||
const websites = await getUserWebsites(auth.user.id, query);
|
||||
|
||||
return json(websites);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue