build: 🔒️ Add extra user check in api
This commit is contained in:
@ -1,18 +1,15 @@
|
||||
import { withSentry } from '@sentry/nextjs'
|
||||
import { DashboardFolder, User } from 'db'
|
||||
import { DashboardFolder } from 'db'
|
||||
import prisma from 'libs/prisma'
|
||||
import { NextApiRequest, NextApiResponse } from 'next'
|
||||
import { getSession } from 'next-auth/react'
|
||||
import { methodNotAllowed } from 'utils'
|
||||
import { getAuthenticatedUser } from 'services/api/utils'
|
||||
import { methodNotAllowed, notAuthenticated } from 'utils'
|
||||
|
||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
const session = await getSession({ req })
|
||||
|
||||
if (!session?.user)
|
||||
return res.status(401).json({ message: 'Not authenticated' })
|
||||
const user = await getAuthenticatedUser(req)
|
||||
if (!user) return notAuthenticated(res)
|
||||
|
||||
const id = req.query.id.toString()
|
||||
const user = session.user as User
|
||||
if (req.method === 'GET') {
|
||||
const folder = await prisma.dashboardFolder.findUnique({
|
||||
where: { id_ownerId: { id, ownerId: user.id } },
|
||||
|
Reference in New Issue
Block a user