fix(api): allow uploading without private token

This commit is contained in:
Nguyen Thanh Quang 2022-07-05 21:05:20 +07:00 committed by GitHub
parent bfa86e9249
commit 6f513265aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 2 deletions

View File

@ -13,9 +13,10 @@ const uploader = multer({
});
async function handler(req: NextApiReq, res: NextApiRes) {
const usr = await req.user();
if (req.method !== 'POST') return res.forbid('Invalid method');
if (!req.headers.authorization) return res.forbid('Unauthorized');
const user = await prisma.user.findFirst({
if (!(req.headers.authorization || usr)) return res.forbid('Unauthorized');
const user = usr || await prisma.user.findFirst({
where: {
token: req.headers.authorization
}