Check session for decrypt, check session and admin for encrypt

This commit is contained in:
austinkelsay 2024-09-30 20:41:52 -05:00
parent 7953bb641f
commit 107f6b4499
2 changed files with 16 additions and 0 deletions

View File

@ -1,10 +1,18 @@
import { nip04 } from 'nostr-tools';
import { getServerSession } from "next-auth/next"
import { authOptions } from "@/pages/api/auth/[...nextauth]"
export default async function handler(req, res) {
const session = await getServerSession(req, res, authOptions)
if (req.method !== 'POST') {
return res.status(405).json({ error: 'Method Not Allowed' });
}
if (!session) {
return res.status(401).json({ error: 'Unauthorized' });
}
const { encryptedContent } = req.body;
if (!encryptedContent) {

View File

@ -1,10 +1,18 @@
import { nip04 } from 'nostr-tools';
import { getServerSession } from "next-auth/next"
import { authOptions } from "@/pages/api/auth/[...nextauth]"
export default async function handler(req, res) {
const session = await getServerSession(req, res, authOptions)
if (req.method !== 'POST') {
return res.status(405).json({ error: 'Method Not Allowed' });
}
if (!session || !session.user.role?.admin) {
return res.status(401).json({ error: 'Unauthorized' });
}
const { content } = req.body;
if (!content) {