mirror of
https://github.com/umami-software/umami.git
synced 2026-02-12 08:37:13 +01:00
Feat/um 114 roles and permissions (#1683)
* Auth checkpoint. * Merge branch 'dev' into feat/um-114-roles-and-permissions
This commit is contained in:
parent
a4e80ca3e5
commit
06bebadbb9
27 changed files with 331 additions and 482 deletions
|
|
@ -1,9 +1,10 @@
|
|||
import { Team } from '@prisma/client';
|
||||
import { NextApiRequestQueryBody } from 'interface/api/nextApi';
|
||||
import { canCreateTeam } from 'lib/auth';
|
||||
import { uuid } from 'lib/crypto';
|
||||
import { useAuth } from 'lib/middleware';
|
||||
import { NextApiResponse } from 'next';
|
||||
import { badRequest, methodNotAllowed, ok } from 'next-basics';
|
||||
import { badRequest, methodNotAllowed, ok, unauthorized } from 'next-basics';
|
||||
import { createTeam, getTeam, getTeamsByUserId } from 'queries';
|
||||
export interface TeamsRequestBody {
|
||||
name: string;
|
||||
|
|
@ -17,16 +18,20 @@ export default async (
|
|||
await useAuth(req, res);
|
||||
|
||||
const {
|
||||
user: { id },
|
||||
user: { id: userId },
|
||||
} = req.auth;
|
||||
|
||||
if (req.method === 'GET') {
|
||||
const teams = await getTeamsByUserId(id);
|
||||
const teams = await getTeamsByUserId(userId);
|
||||
|
||||
return ok(res, teams);
|
||||
}
|
||||
|
||||
if (req.method === 'POST') {
|
||||
if (await canCreateTeam(userId)) {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
const { name } = req.body;
|
||||
|
||||
const team = await getTeam({ name });
|
||||
|
|
@ -36,7 +41,7 @@ export default async (
|
|||
}
|
||||
|
||||
const created = await createTeam({
|
||||
id: id || uuid(),
|
||||
id: uuid(),
|
||||
name,
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue